There shuffle mode (i.e. the Shuffle Playback) is a function available on the main music players and modern music streaming services that allows you to play the songs contained in a folder or playlist in an – apparently – random way. Even though you use this function assiduously, it may be that you are not aware of its complex functioning due to the fact that its algorithms are intertwined with the psychology of the perception of patterns by us human beings.
Early shuffle algorithms did exactly that: they listed songs for playback in a completely random order. Already in the early 2000s, however, many users complained that the result was not so random, for example when two songs by the same artist happen in a row. In reality this is an expected eventuality in a perfectly causal list, like the fact that when throwing a data item it can happen that a number comes up 2 times in a row. To avoid these “coincidences”, large companies active in the sector have started to make the less random algorithms “forcing” a greater distance between songs belonging to the same logical group (same artist, same album, same genre and so on).
As he said Steve Jobs During the official launch of the iPod Shuffle in 2005, the ultimate goal of this change was to “make it less random to do so seem more casual.” This principle was then also applied in other algorithms that we use every day.
How shuffle algorithms work
A classic example of a random algorithm for playing songs in shuffle isFisher-Yates algorithm. Conceptually, this algorithm takes a list of all the elements in the sequence and determines the next element in the shuffled sequence by randomly extracting an element from the list, until no others remain.
To increase the sensation of chance, however, Fiedler devised an alternative playback algorithm, a version of which is used today for example by the music streaming platform Spotify. In essence, the algorithm divides the music collection into multiple logical groups, and divides the songs according to the principle of maximum diffusion for each logical group. Fiedler explains:
The tracks within each group are shuffled to obtain a random playing order and, in case the group is still divisible into subgroups (for example, you grouped it into genres, now you subgroup it into artists), for this step Balanced Shuffle algorithm is used. In this way, the algorithm is applied recursively until no further classification is possible. In this case, the remaining tracks of this subgroup are considered equal in style and can therefore be mixed using a conventional method. Once the song lists for all the groups have been collected, the main part of the algorithm begins: the playlists per group are merged into one, respecting the principle of maximum diffusion.
How does this algorithm solve the problem of the false perception of lack of randomness? In an article published on its official blog, Spotify explains it with this example:
Suppose we have a playlist containing some songs from The White Stripes, The xx, Bonobos, Britney Spears And Jaga Jazzist. For each artist we take her songs and try to distribute them as evenly as possible across the entire playlist. Then we collect all the songs and sort them based on their location.
The algorithm takes into account the duration of a playlist he was born in number of songs present for each type. So, going back to the previous example, if there are four White Stripes songs in the list, each of them should be offered approximately every 25% of the playlist length. Furthermore, the algorithm introduces a random offset at the beginning, so that all the first songs do not end up in position 0 and, to obtain a result that seems as random as possible, songs by the same artist are also mixed together.
Why random playlists don't seem random to us: the “gambler's fallacy”
If we have to put two , known as gambler's fallacy, in which the perceived probability of an event is altered by what has happened in the past: for example, if 57 is drawn in the wheel of Naples this week we will tend to think that next week it will be very unlikely that the same number will be drawn again in the same wheel, but in reality the probability is always the same, i.e. 1/90. Similarly, if we listen to a song by a given artist it will seem very unlikely that the next song is by the same artist, which is why when it happens we don't perceive it as a random event – even if it is.
As the software engineer said Martin Fiedler on his blog, «the problem with conventional shuffle algorithms is that they are too random. They lack equity and uniform distribution.” Our brain loves to look for patterns and randomness and for this reason it interprets randomness as not really random if the same artist plays more than once at too close a distance.