Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Pick-random-element/Jq/pick-random-element-1.jq
Normal file
1
Task/Pick-random-element/Jq/pick-random-element-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
< /dev/urandom tr -cd '0-9' | fold -w 1 | jq -MRcnr -f program.jq
|
||||
11
Task/Pick-random-element/Jq/pick-random-element-2.jq
Normal file
11
Task/Pick-random-element/Jq/pick-random-element-2.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Output: a prn in range(0;$n) where $n is `.`
|
||||
def prn:
|
||||
if . == 1 then 0
|
||||
else . as $n
|
||||
| ([1, (($n-1)|tostring|length)]|max) as $w
|
||||
| [limit($w; inputs)] | join("") | tonumber
|
||||
| if . < $n then . else ($n | prn) end
|
||||
end;
|
||||
|
||||
# An illustration - 10 selections at random with replacement:
|
||||
range(0;10) | ["a", "b", "c"] | .[length|prn]
|
||||
Loading…
Add table
Add a link
Reference in a new issue