This script can select random files (if I remember correctly, the random option was added for a car mp3 player, as it happens):
There's also this, which is an earlier version of the same thing, before it was combined into a command that does lots of other things. May be useful if you just want to look at how it's done: