≈ volna.computerSince February 2026
← My notes

A playlist with 27 ways to shuffle

Take a playlist containing A, B and C, in that order. Starting at the left, visit each slot and swap its contents with the contents of a slot chosen uniformly from the whole list. Allow a slot to swap with itself. Assume each random choice is independent. If you press shuffle, how often should B end up between A and C in the original order?

Write down the positions you picked for the swaps. Picking the first slot, then the second, then the third leaves ABC alone. Picking the second slot, then the first, then the third also gives ABC. Two swaps cancel each other out. The player can take 27 different paths through this loop. There are 6 possible running orders, and 27 divided by 6 is 4.5. Giving every order an equal number of paths is impossible.

For a test, replace the random picker with a function that reads positions from a list. Reset the playlist to ABC before each run and feed the function every legal list of picks. Counting the outputs gives ABC, CAB and CBA 4 times each. The other orders appear 5 times each. A test that checks for missing or duplicated songs passes on every run.

Now fill the last slot first. Pick any of the 3 songs for that slot, swap it into place and leave it there. Pick either of the 2 remaining songs for the middle. Run the same counting test over those 6 pairs of picks. ABC comes up once, when C stays at the end and B stays in the middle. Each of the other orders also comes up once.