Which of these twenty films tonight? I’m happy to let shuf, part of GNU coreutils, decide.
Give it a file and ask for a few lines:
shuf -n 3 films.txt
Without -n you get the whole file in random order. You can also hand it the choices on the command line, or a range of numbers:
shuf -n 1 -e pizza soup curry
shuf -i 1-100 -n 1
By default each line is used at most once, which suits drawing names for a secret Santa. Add -r to allow repeats, for example to roll a die ten times:
shuf -r -i 1-6 -n 10
It reads standard input too, so it fits at the end of a pipe. A sample of random files is a nice way to spot check a backup:
find /mnt/photos -type f | shuf -n 5
Then open those five and see that they load.
One warning: don’t write the result back to the file you are reading with >, because the shell empties it first. Use -o instead if you want to shuffle a file in place. This is for casual randomness, and I wouldn’t use it to make passwords or keys. macOS doesn’t ship it under that name.
Further reading: shuf invocation