I'm not entirely certain why this is so hard, but I (and many, many people around the web) agree. The most miraculous thing to me is that "play files randomly forever" is the _ONLY_ mode I ever want VLC to use for my music, and yet I have never managed to get a version of VLC that can do that sanely (though I've read that specific point releases did manage to get it right until somebody reverted the change).
Point 1 -- Why is it "random" the same way every time?
I strongly suspect that whoever is shuffling is just using rand() from the C runtimes. That is "random enough", assuming that you bother to seed the generator with srand(). If not, the seed will always be the same (zero, I believe), so the shuffle will always be the same.
As an example:
http://www.cplusplus.com/reference/clib ... dlib/rand/
The critical part there is simply:
Code: Select all
/* initialize random seed: */
srand ( time(NULL) );
Point 2 -- But when it repeats, it plays the songs in the same order as before!
VLC appears to only shuffle the playlist once, and then repeat that shuffled playlist indefinitely. It's not particularly hard to fix that::
1. Load playlist
2. Shuffle playlist (like a deck of cards -- randomly pick two indices and swap them, repeat a lot)
3. Play playlist
4. When you reach the end of the playlist, if you are supposed to play forever, goto step #2 (as opposed to what VLC appears to do, which is "goto step #3")
It is possible to get a repeat when you reach step 4 and jump to step 2. Personally, I don't think it's worth trying to fix that, because if you've got 100+ songs, the likelihood is pretty low... But I'm sure somebody will complain that "every so often I get a song repeated really close together."
Point 3 -- But I can't stand any repeats!
You can protect against that with a few more steps, though this introduces a different structure (which hopefully won't stand out for large playlists):
1. Load playlist
2. Shuffle entire playlist (breaks up sequencing -- will discuss after algorithm)
3. Shuffle front half of playlist (will make sense when we hit the loop)
4. Play front half of playlist
5. Shuffle back half of playlist
6. Play back half of playlist
7. If repeating, goto step #3
Step #2 may seem irrelevant, but if you don't do it, you get (for example) all your artists named A-M playing together and all of them named N-Z playing together. So we do one quick shuffle up front, and then we shuffle+play the halves. It is now impossible to have a song repeat in less than half the playlist length, which is the most you can possibly hope for. If you want longer spans between repeats, then you basically have to do what VLC does now, which is build up one mix-playlist and just keep repeating it. That doesn't work for me, 'coz my subconscious learns the mixed ordering and starts pre-playing music before it actually starts. That's why I'm kind of a stickler for reasonable and sane shuffling...