# An algorithm to play random music

Ángel Ortega

Are you playing your huge music library in random mode for hours or days and fed up of listening the same fucking songs all over again, while never hearing others? So do I.

Regardless of what Steve Jobs and other morons think, their music players are fucked up, specially their shuffle functions. Music players running in random mode should keep the last time a song was played into account.

This is the algorithm to select which song to play next:

1. Sort all songs by the last time they were played, in ascending order (never played ones fall at the beginning of the list, recently played songs fall at the end).
2. Pick a given set from the beginning of the list (like, say, the 10% of them).
3. Pick one song from this set at random.
4. Get the author of this song and test if another song by the same author was played recently (like, say, the 10% of the last played songs). If it is, jump back to previous step.
5. store current time as its playing time, and play it.

This way, new songs added to the set have the higher chance of being played soon, as they are at the top. Songs played a long time ago will follow. And the song that have just played won't be heard for a long time.

Implement this in your music players, scumbags.

Update: I've improved the algorithm by adding a step that spreads the authors.