The DJ Who Shuffled Every Song and Still Got Track Seven

The DJ Who Shuffled Every Song and Still Got Track Seven

About halfway through a twelve-track album, the DJ hears a familiar transition. The sixth song has just ended, the opening notes of the next one come through the speakers, and somebody at the other end of the room says, “I thought you put this on shuffle.” The DJ checks the display. Sure enough, the seventh song on the album is playing seventh.

I sympathize with the listener. If I bothered to shuffle an album and then heard a song exactly where I expected to hear it, I might check the display myself. But before we send the equipment out for repair, let me offer a wager. Which is more likely on a fair shuffle: that every song moves to a different position, or that at least one winds up right where it started?

I’ll take the second bet. On a twelve-track album, it wins about 63.2 percent of the time.

A three-song experiment

Let’s give the DJ a three-song EP and call the tracks A, B, and C. They appear on the original recording in that order. For our experiment, the player uses each song once, and each of the six possible running orders has the same chance of appearing. You can check the wager yourself by covering the right-hand column and looking for songs that kept their seats.

Running order Songs in their original positions
ABC A, B, and C
ACB A
BAC C
BCA None
CAB None
CBA B

Only BCA and CAB move every song. Even playing the album backward leaves B sitting comfortably in the middle. Four of the six orders give our suspicious listener something to point to, so the bet on at least one match wins two times out of three.

The two orders in which everything moves have a name. Mathematicians call each one a derangement, a word I would have reserved for the fellow keeping written records of what the DJ played.

When did you make your prediction?

Back at the twelve-track album, suppose you write “track seven will play seventh” on a slip of paper and hand it to the DJ before he presses shuffle. Only one of the twelve slots will satisfy that prediction. Your chance of being right is one in twelve, or about 8.3 percent.

Now put the pencil away and listen to the whole album. If track two plays second, you can point that out. If track nine plays ninth, you can point that out just as readily. By the end of the evening, you may remember one striking coincidence, but the shuffle had twelve opportunities to supply it.

There is a wrinkle in working out those odds. The twelve opportunities depend on one another because every song uses up a slot. Imagine that eleven songs have somehow kept their original positions. Where, exactly, do you propose to put the twelfth?

One song, on average

We can answer one question without untangling those dependencies. If the DJ shuffles the album night after night, how many songs per night should he expect to find in their original positions?

Consider the three-song experiment again. Read down the right-hand column and count the matches: three, one, one, zero, zero, and one. That makes six matches distributed across six equally likely playlists, for an average of exactly one. The original order, ABC, contributes three matches all by itself, enough to balance both evenings when nothing matched.

The same reasoning works for twelve songs. Each song has a one-in-twelve chance of keeping its position, so adding the twelve individual chances gives an expected count of exactly one. Put a hundred songs on the playlist, and the arithmetic becomes a hundred times one hundredth. I rather like that trade: every individual prediction gets worse, yet the expected number you get right stays precisely where it was.

Where the 63.2 percent comes from

The average count leaves one piece of the wager unsettled. A playlist with three matches earns the listener the same single win as a playlist with one, so we need to count playlists with a match. We can do that by correcting for the occasions we counted twice, then correcting for the occasions that correction went too far.

The three-song EP shows it in action. Adding the individual matches gave us six, but ABC appeared in that count three times. Subtract the three overlapping pairs of matches, all of which belong to ABC, and we have erased that playlist altogether. Add it back once for the three-way overlap, and the count comes out right: six minus three plus one gives four winning playlists.

For a twelve-track album, the same bookkeeping gives the following probability. The exclamation point means factorial, so, for example, 4! is the product of 4, 3, 2, and 1.

P(\text{at least one match}) = 1 - \frac{1}{2!} + \frac{1}{3!} - \frac{1}{4!} + \cdots - \frac{1}{12!}

Those fractions get small in a hurry. The first four terms already give 62.5 percent, and carrying the calculation through the twelfth gives approximately 63.212 percent. As the playlist grows, the probability approaches a familiar mathematical quantity in an unexpected setting: one minus the reciprocal of Euler’s number. Rounded to three decimal places, that limit is 0.632.

The DJ makes a small adjustment

By the following weekend, the DJ has devised a cure for the complaints. He lets the player generate a playlist, checks it against the back of the CD case, and presses shuffle again if even one song has kept its slot. Eventually a playlist passes inspection, and the evening proceeds without incident.

I wonder how many listeners would judge the new arrangement an improvement. Every song now goes somewhere else, which was what they expected from shuffle in the first place. All the DJ had to do to make his twelve-track album sound properly random was throw away nearly two-thirds of the orders a fair shuffle would have given him.

 

Leave a Reply

Your email address will not be published. Required fields are marked *