Apps & feeds
How Spotify Shuffle Actually Works
A truly random shuffle plays the same artist back to back more often than you'd guess, because clumped orders are exactly as likely as spread-out ones. Listeners heard that as broken. In 2014 Spotify described its fix: spread each artist's songs across the playlist, from a random start, with a little jitter. Both run below.
Go deeper
Change the spread-out shuffle
- Objective
- Describe how the spread-out shuffle places each artist's songs, and why that keeps repeats rare.
- How this step gets you there
- Step through the stage one artist at a time. Each step shows that artist's songs spaced evenly from a random start, then the final sort interleaves them all.
Here's the spread-out shuffle on a stage of its own, with Change. Give artist A more songs and step through again. On this seed it keeps every artist apart up to 7 songs by A. At 8, the same artist plays back to back twice: the more songs one artist has, the less room between them.
The spread-out shuffle, one artist at a time
- CH1 Artist A
- CH2 Artist B
- CH3 Artist C
- CH4 Artist D
Run it on your playlist
- Objective
- Check whether the clumps on your own playlist are what a fair shuffle predicts.
- How this step gets you there
- You type your top artists' song counts, and the model shuffles that playlist 2,000 times each way. Comparing pure random's average with the fair-shuffle math answers whether anything is broken.
Open a playlist you shuffle and count the songs by its top artists, up to four of them and 12 songs each. Type the counts below. The model shuffles your playlist 2,000 times each way. If pure random's average lands on what the math predicts for a fair shuffle, the clumps you hear are what fair sounds like.
Table
| Same artist back to back, per shuffle | Pure random | Spread out |
|---|---|---|
| 0 | 1.5% (30) | 57.8% (1155) |
| 1 | 9.1% (182) | 38.0% (759) |
| 2 | 18.9% (378) | 4.3% (86) |
| 3 | 26.4% (528) | 0.0% (0) |
| 4 | 22.2% (444) | 0.0% (0) |
| 5 | 13.1% (262) | 0.0% (0) |
| 6 | 5.8% (116) | 0.0% (0) |
| 7 | 2.4% (47) | 0.0% (0) |
| 8+ | 0.7% (13) | 0.0% (0) |
2,000 shuffles each. Pure random averages 3.37 same-artist pairs per shuffle, and the math for a fair shuffle says 3.38. Spread out averages 0.47.
Questions
- Is Spotify shuffle really random?
- Random, but not evenly random. Spotify used the Fisher–Yates shuffle, where every order is equally likely. Listeners complained about hearing one artist twice in a row, so in 2014 Spotify described a shuffle that spreads each artist's songs out. Its orders are still random, but clumped ones are now much rarer.
- Why does true random feel clustered?
- Because clumps are common. Over a whole playlist, the small chance that each pair of neighbours shares an artist adds up to several repeats. People notice the repeats and not the gaps, and read a pattern into them. Spotify's 2014 post calls this the gambler's fallacy.
- Is this Spotify's actual code?
- No. Spotify hasn't published its code. This is a model of the algorithm its engineering blog described in February 2014, checked against a plain Python copy on hundreds of random playlists. Spotify may have changed its shuffle since.
- What is the Fisher–Yates shuffle?
- It walks back from the last slot of the playlist. At each slot it picks one of the songs not yet placed, at random, and swaps it into that slot. Every order comes out equally likely, in a single pass.
Practice the pattern
The spread-out shuffle starts by grouping songs by artist in a hash map. Group Anagrams drills the same move: group items by a key, then work through each group.