There is a useful command in the
randomize-lines package namely “
rl“. It reads lines from the standard input and shuffles them. It can also be used to pick a random line from a text file.
Let’s see some examples from the man:
Play a random sound after 4 minutes (perfect for toast):
sleep 240 ; play `find /sounds -name ´*.au´ -print | rl --count=1`
Play the 15 most recent .mp3 files in random order.
ls -c *.mp3 | head -n 15 | rl | xargs --delimiter=´\n´ play
Roll a dice:
seq 6 | rl --count 2
Roll a dice 1000 times and see which number comes up more often:
seq 6 | rl --reselect --count 1000 | sort | uniq -c | sort -n
Shuffle the words of a sentence:
echo -n "The rain in Spain stays mainly in the plain." \ | rl --delimiter=´ ´;echo
Find all movies and play them in random order.
find . -name ´*.avi´ -print0 | rl -0 | xargs -n 1 -0 mplayer
-0 is used filenames with spaces (even newlines and other unusual characters) in them work.