logoalt Hacker News

WalterBright • today at 4:11 AM • 3 replies • view on HN

To implement shuffle play, it is not necessary to actually shuffle filenames in memory. Just generate a random number modulo the number of files, and then play that file. That way your program can shuffle play any number of files, no worries about running out of memory.

By the way, the Roku box has a "media player" app in it by default, and it cannot shuffle play more than a handful of files. Completely useless.


Replies

shakow • today at 6:39 AM

> Just generate a random number modulo the number of files, and then play that file

That won't be uniform. If you want really random shuffle, mod to the closest next power of 2 then re-sample until you get a number within the bounds.

WalterBright • today at 4:18 AM

BTW, Windows Media Player is the winner, as it "just works". Just point it at the root directory of the music files, turn on shuffle play, and it works, and doesn't crash.

moron4hire • today at 4:30 AM

That's random play, not shuffle play. Random play can repeat songs before all songs are played. Shuffle play will play all songs exactly once before any repeats occur. Random play "puts the card back into the deck" before dealing the next one.

➕ show 1 reply