Hacker News new | ask | show | jobs
by 0gs 19 days ago
wow hacker news wins again. i am going to fix these in my music player. i think 2 & 3 are chill already... and i can totally fix 1. thanks!
1 comments

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.

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.
You are correct, and that matters if it is a small number of music files. If it is a large number of files, the difference in user experience is irrelevant. But not needing to remember what was already played keeps the player memory footprint small.
Except "small" is very large because this runs face first into the birthday problem so the average distance between duplicates grows to the square root of the number of files.

Hell even actual shuffling is not necessarily enough to "feel" right for human psyche, famously despite the ipod doing actual shuffling[0] users complained because tracks of the same artist / album could still cluster over shuffling an entire library, so they implemented "smart shuffle" to skew the shuffle and break up clusters. An other option is to weight the random pick by how far back a track was last played, or how little it's been played overall. This has the advantage of favouring less played tracks across listening sessions.

[0] and frankly if the ipod was able to do actual shuffling back in 2005 the memory footprint is just a lazy excuse

Isn't this just over-engineering it? It's not like one is gambling with money on what song is played next.
> Isn't this just over-engineering it?

When users are complaining that your shuffle is hot garbage, it's just engineering.

> It's not like one is gambling with money on what song is played next.

Which... is rather the point? If one was doing that, your scheme would be fine.

> 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.

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.