Better Shuffle Algorithm / Ideas

Type: Music, Algorithm, Programming
Drafted: 2017.09.26
Posted: 2017.10.10
Status: In Progress - Working on PoC

I use shuffle to listen to my music library. Although shuffle is terrible! Shuffle frequently picks the same songs, even though I constantly skip them, and it rarely plays other songs. Shuffling shouldn't be this difficult!

Here is an outline for anyone to use, please fix your shuffles!

Goals

  • Give importance to
    • Songs recently added to music library
    • Last played a long time ago
    • Consecutive plays of same song
  • Penalize a song for being skipped
  • Be fast enough to operate on most mobile devices
  • Self-balance
    • If no new songs are added for a long period of time, still be able to provide a quality shuffle algorithm

Approach

Every category has a weight (specified in parenthesis). Weight corresponds to the category's positive or negative influence. Positive influence means the category should be used to more likely pick a song, negative influences means that category should be used to less likely pick a song.

Skipping (-45%)

Percentages below represent a point of time in a song. Example, if a song is 3 minutes (180 seconds) long, then 0% - 10% is 0 seconds - 18 seconds.

  • 0% - 10% - largest effect (1.0)
  • 11% - 19%
  • 20% - 39%
  • 40% - 59%
  • 60% - 79%
  • 80% - 89%
  • 90% - 99% - very very small effect
  • 100% - not skipped/no effect (0.0)

* Backward skips do not count

Skip weight should be calculated with the result of the last 10 plays. For example if a song isn't skipped then skipped at varying positions, it might look something like this:

0 + 0 + 0 + 0.1 + 0.25 + 0.5 + 1  + 1 + 1 + 1 = 4.85 / 10 = 0.485 * .45 = 0.21825

* The above weights were arbitrarily picked (untested)

Last Played (+10%)

If the song was last played weeks or months ago, shuffle should be more likely to pick it.

Last Played Cateogries:

  • Last week - very small effect (<= 0.05)
  • Last 2 weeks
  • Last month
  • 1 - 2 months
  • 2 - 3 months
  • 3 - 6 months
  • 6+ months - largest effect (1.0)

Date Added (+40%)

If I just added a song to my collection, I want to hear it. Most of the time when I add new songs, they don't get thrown into the top of the shuffled list. So I have to directly go to the song and play it.

  • Last week - largest effect (1.0)
  • Last 2 weeks
  • Last month
  • More than 1 month - very small effect (<= 0.05)

Consecutive Times Played (+5%)

I add a song to my collection, and play it 5 times in a row. I like this song.

  • 6+ times - largest effect (1.0)
  • 2 - 5
  • 1 - smallest effect (<= 0.05)

Positional Importance

If a song has been selected in the top 10 spots the last 3 times, maybe it's time to move it down to 11 - 20, and bump up a song from 10 - 20. If I'm in the car, most trips are 15 - 25 minutes. Which is 5 - 10 songs depending on length. The first 10 songs the algorithm selects is very important. I don't want to spend time skipipng, I want to enjoy listening to my music collection.