triptico.com

Un naufragio personal

An algorithm to play random music

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.

Visitor comments

jww
2011-06-07
What does qualify you to describe as "morons" and "scumbags" great men like Steve Jobs and Bill Gates? What have you done?

Angel Ortega
2011-06-07
jww, you must be joking with that "great men" argument.

What have I done? Many things, but keeping on topic, an algorithm for random playing music that doesn't suck.

jww
2011-06-07
No, I'm not joking.

Certainly sometimes some songs are played repeatedly on my iPhone but that is what "random" means.

Angel Ortega
2011-06-07
No, that is not what "random" means regarding music playing. It's meant to be a pleasant stream of evenly placed themes from a given set instead of the same bunch of a few over and over again.