How to Shuffle and Sample on the Command-Line
blog.jpalardy.com
blog.jpalardy.com
Good to know things are still getting better in coreutils!
shuf -r -z -n 100 -e 1 2 3 4 5 6;echo -e "\n"
And rolls of a non-transitive (Grime) die shuf -r -z -n 100 -e 3 3 3 3 3 6;echo -e "\n"
Which is timely. I sometimes forget how flexible the terminal prompt is...https://twitter.com/pixelbeat_/status/587703133717057537
paste -d '' <(printf '%s\n' $(seq 2 9) T J Q K A | sed 'p;p;p') \
<(yes $'H\nD\nS\nC' | head -n52) |
shuf -n5 > 1..100 | Get-Random
72
> 1..100 | Get-Random -count 3
16
96
56
but doesn't have something like -r to resample. Or a nice way to simply shuffle the whole collection (workaround is to just pass -count as large or larger than the collection). sort -r | head -n100
but obviously this requires the entire file to be shuffled before printing the first 100 lines. awk "BEGIN { srand($RANDOM) } { print int(rand() * 1000000), \$0 }" | sort -n | cut -d' ' -f2-
to shuffle an input awk "{print rand(), $0}" | sort -g | cut -d' ' -f2-
which is shorter allows more than 1,000,000 random values, namely ~52bits in awk's 64bit implementations. man shuf $ man -k shuffle
gives
pstops (1) - shuffle pages in a PostScript fileI wish I knew about shuf. I've been using sort -R or using Python.
man coreutils
?ooh topical:
ls /usr/bin | shuf -n1 | xargs man http://linux.die.net/man/1/shuf
since if it's not on the internet, how will anyone ever find it?