How Fisher-Yates Shuffling Works, Without Heavy Math
Published on
Shuffling a list looks simple, but there are wrong ways to do it. The most common is sorting the list by random numbers, which, depending on the implementation, favors certain orders. The correct method has a name: Fisher-Yates.
The idea is to walk through the list from the end to the start. At each position, pick an index between the start of the list and that position, inclusive, and swap the current item with the picked one. When the walk ends, the list is shuffled and every possible order has exactly the same chance.
The delicate part is picking the index. If you take a very large random number and use the remainder after dividing by the desired size, the first values come up slightly more often than the rest whenever the size does not divide the number space evenly. The fix is rejection: discard the leftover values and draw again. That way each index has the same chance.
With the public seed, the shuffle is deterministic. The same inputs always give the same order, and that is what makes verification possible. The first winner is the first item of the shuffled list, the second is the next, and so on.
In the team draw, the same shuffled list is dealt out in rotation.
The algorithm page shows the full code so you can redo the calculation.