UnipickerDraw Whitepaper
Algorithms · LESSON 3

Fisher–Yates — shuffling entrants

Weighted draw

A way to shuffle entrants "truly fairly" and set the order (their seats). Fair means every ordering comes up with equal probability.

The whole trick is one thing — fill one seat at a time with "anyone among the remaining entrants." Entrants shuffle as they change seats.
Concept

Can't we just shuffle randomly?

Just "pick two entrants and swap seats" many times, right? But nobody knows how many times is enough, and some orderings come up more often, so it may not be fair. Fisher–Yates finishes perfectly fair in exactly one pass.

Concept

Core idea — "fill one seat at a time"

There are 5 seats (the order). Starting from the last seat, decide "who sits here?"

  • Last (5th) seat → any 1 of 5 people (5 options)
  • The next (4th) seat → 1 of the remaining 4 (4 options)
  • 3rd seat → 1 of the remaining 3 … and so on down to the 1st

In the computer, the picked entrant just "swaps seats" with the one in that seat. Entrants shuffle by changing seats.

Experiment

Follow it seat by seat

Seat being setRemaining candidatesJust-picked entrantLocked seat
Why it's fair

Count it yourself

There are 5×4×3×2×1 = 120 ways to line up 5 entrants. Fisher–Yates picks "anyone among the remaining" at each seat, creating 120 paths, and each path makes a different ordering exactly once → every ordering is exactly 1/120.

With a small case of 3 (A·B·C), it is 3×2×1 = 6 ways.

Case1st seat2nd seat3rd seat
1ABC
2ACB
3BAC
4BCA
5CAB
6CBA
Each of the 6 orderings appears exactly once, right? So every ordering has equal probability = fair. (To check over thousands of runs, see "Shuffle 10,000 times" below.)
Verify

Is it really fair? — check over many shuffles

How many times "entrant No. 1" sat in each seat. If the bars are even, it is fair.

Total shuffles 0

In one line — from the last seat, pick anyone among the entrants up to that seat and swap. One pass and you are done; every ordering has equal probability.
menu_bookReferences
  1. Durstenfeld, R. (1964). Algorithm 235: Random Permutation. Communications of the ACM, 7(7), 420.
  2. Fisher–Yates Shuffle. Wikipedia. en.wikipedia.org/wiki/Fisher-Yates_shuffle