← All writing
Mathematics 11 min read Free

Fairness Lies Where the Eye Cannot See

What is essential is invisible to the eye. —Antoine de Saint-Exupéry, The Little Prince

Horris Tse
Horris Tse Founder · HtPi
Save

We usually judge whether a deck has been properly shuffled by sight. Cards that once sat together have been separated; reds and blacks are interspersed; the numbers seem to follow no discernible pattern. It looks shuffled, so we assume it is.

Yet whether the shuffle is truly fair is hidden precisely behind that visible illusion. To disorder those same 52 cards, a riffle shuffle takes at least seven rounds and an overhand may take thousands — while a computer needs exactly 51 steps. Why should the answers differ so widely? The reason is one only the mind can see.

Before a game begins, someone always picks up the whole deck, splits it deftly into two, and lets the corners fall together. With a soft riffle, the tidy order breaks apart. Two or three shuffles more, and the eye can no longer see a pattern; no one at the table usually asks for proof.

But losing the visible pattern is not the same as losing the order. A deck can look thoroughly mixed while its original sequence still hides inside — some arrangements far likelier to appear than others, which barely stand a chance.

This is not the cards having memory. It is only that every way of shuffling has its own rules of motion, and those rules limit where each card can travel. As long as the limits hold, the traces of the previous order have not truly disappeared.

52! ≈ 8.07 × 1067

52 distinct cards can be arranged in this many orders.

“Shuffling fairly”, then, is not merely making the next card unguessable. The stricter meaning is this: of these 52! orderings, every single one should have an equal chance of appearing.

Shuffling by hand can only wear the old order away through one motion after another. A computer, facing the same goal, need not use the same method at all.

The cards have scattered, yet the order has not gone

Start with the most familiar: the riffle shuffle — split the deck roughly in half, then let the two halves fall together.

On the surface, the cards have moved a great deal; but within each half the order is largely preserved. Suppose we begin with 1 to 52. After one shuffle we can usually still find two upward-continuing runs in the new order. Mathematicians call them rising sequences. Shuffle again and there are at most four; once more, at most eight. Each shuffle pulls the old order apart, but never erases it in a single stroke.

In 1992, Dave Bayer and Persi Diaconis wrote this shuffle as a precise model and measured how far the shuffled order sat from truly uniform randomness. The result is not a smooth slope: at the fifth shuffle the gap is still large; only between the sixth and the seventh does a clear drop appear. This sudden crossing of a threshold is called cutoff.

So the most widely repeated answer is this: for 52 cards, a riffle needs at least seven shuffles to be well mixed.

After seven, is it completely random?

No. In the Bayer–Diaconis table, six riffle shuffles sit about 0.614 in total variation distance from the uniform distribution; seven falls to 0.334, eight to 0.167. The seventh matters because it crosses the main steep descent — not because mathematics stamps a “pass” certificate at seven.

And this conclusion rests on the Gilbert–Shannon–Reeds model: the cut position follows a particular distribution, and the two halves interleave in proportion to the cards remaining in each. In the real world some people shuffle well, others little better than stacking the two halves back together; “seven” is no guarantee for any pair of hands.

The same act of shuffling, answers a hundredfold apart

If you cannot riffle, you might use the overhand shuffle: draw a small packet from the cards in one hand into the other, then return it above or below the remaining pile. It too has cutting, moving, recombining — the trouble is that many neighbouring cards stay together as a group. The order is disturbed, but taken apart very slowly.

Robin Pemantle analysed a model of the overhand shuffle in 1989. For 52 cards, his numerical evidence was this: reaching a range reasonably close to uniform randomness may take 1,000 to 3,000 shuffles. This does not mean you must really shuffle three thousand times before each evening’s game; it shows that two seemingly similar motions can differ completely in how efficiently they mix.

There is another approach still: spread all the cards on the table and push them around with both hands — the so-called wash. It can break up a great many neighbour relations at once, and often works well; the cost is just as plain: it takes space, takes time, and leaves you to gather all 52 cards back one by one.

Looking well mixed, and every outcome being equally likely, are two different things.

A deck that looks every which way does not mean every ordering is equally likely. Conversely, a procedure with no cards flying at all — repeating just 51 simple steps — can write fairness into its very structure.

On a computer, which shuffle should we simulate?

Suppose you are not at the card table but writing an online game. There are 52 cards on the screen, and they need shuffling before the deal. The natural question seems to be: should the program simulate the riffle, the overhand, or spread the cards out to wash?

But a computer has no hands, no friction of paper, no table that must be cleared. Simulating all of that is of course possible; only, if the aim is purely a fair new ordering, those details are not the point.

Hidden here is a distinction easily missed: simulating how hands shuffle is one problem; producing a fair new ordering is another.

The Fisher–Yates shuffle solves exactly the latter.

Don’t imitate the hands; work on the order directly

Picture 52 cards in 52 positions. Handle the last one first: from all 52 cards (itself included) choose one at random and swap it in. The last position is now fixed and never moves again.

Next, the second to last: choose at random from the remaining 51 and swap. Then from 50, from 49… steadily narrowing the range until only the first card is left.

for i from 51 down to 1:
    j = random integer from 0 to i
    swap(deck[i], deck[j])

Fifty-two cards need only 51 steps. If a step happens to draw itself, two different cards need not really be exchanged at all; so, precisely, it is 51 random choices, not necessarily 51 actual swaps.

Why is it fair? The first step already tells you: every card’s chance of reaching the last position is 1/52. Once the last position is fixed, every remaining card’s conditional chance of reaching the second-to-last is 1/51. And so on, so the chance of any one specified ordering appearing is:

1/52 × 1/51 × … × 1/2 = 1/52!

No ordering holds an extra lottery ticket. As long as each random choice is itself fair, all permutations end up equally likely.

Is this really what Fisher and Yates originally designed?

The idea comes from the 1938 statistical tables of Ronald Fisher and Frank Yates: with no line of code to call for a random number, they used a table of random digits to draw, item by item, from those not yet chosen. In 1964, Richard Durstenfeld rewrote the method into the in-place swap version common today; Donald Knuth later made it widely known among programmers.

So today’s “Fisher–Yates shuffle” usually means this back-to-front, range-narrowing version; some also call it the Knuth shuffle.

Looking very random, and still not being fair

The Fisher–Yates code is short enough to tempt everyone into rewriting it. The most common mistake is to handle each card in turn, but every time swap it with any card chosen from the whole 52-card deck. It certainly makes the cards look thoroughly mixed; the problem is that different orderings have different numbers of paths that reach them.

There is a flaw you can see without counting term by term: this approach has 5252 possible paths, but they must divide evenly among 52! orderings. The former is not divisible by the latter, so it is impossible for every ordering to receive an equal share. The surface fooled us; the arithmetic gives it away.

There is another common shortcut: instead of writing a shuffle, just tell the program to sort the deck “at random”. The single line below means that whenever the sorter picks up two cards to compare, the program tosses a coin on the spot and answers at random which one should come first:

deck.sort(() => Math.random() - 0.5)

The trouble is that the sorter does not scatter all the cards at random in one go; it compares different cards repeatedly and adjusts their positions step by step from earlier answers. In a proper sort, the answers must stay consistent: if it first learns A comes before B, and B before C, it must not later be told C comes before A. The line above draws afresh each time, so the same pair, compared again, may get the opposite answer. The sorter then works from a set of mutually contradictory instructions; which orderings turn up most often ends up depending on which sorting steps the browser actually uses — it does not naturally become an equal chance across six, let alone 52!, orderings.

This is also why Fisher–Yates suits an ordinary computer program better than simulating hands. Not because it is more like real shuffling; quite the opposite — it strips away every unnecessary physical detail and keeps only what we truly need: to draw one ordering fairly from all permutations.

The time to run it is merely linear in the number of cards; each step’s behaviour can be checked clearly, item by item; and its fairness can be proved directly from its structure. Insist on simulating the riffle and we must still decide how precise the cut is, the probability of each card falling, whether the hands are the same every time. The more a model resembles reality, the closer to the goal it need not be.

Still, a fair algorithm does not make the whole system fair.Fisher–Yates assumes the random integer obtained at each step is itself unbiased. Ordinary pseudo-random numbers are enough for many games; where money, security, or verifiable fairness is involved, the random source, its seed, the sampling method, and the auditing all have to be handled separately. A good shuffle algorithm cannot save a bad source of randomness.

What truly needs keeping is not the shuffling motion

The real world does not only hand us the problem; it often throws in a familiar solution too. Shuffling by hand relies on cutting, stacking, pushing, colliding; when cards move into a computer, we naturally want to carry that whole string of motions along.

But a deck’s “fairness” does not live in the gestures. It lives in whether every ordering has the same chance.

See that clearly and the question changes: we no longer ask how the computer can shuffle like a person, but how to generate a fair permutation directly. Fisher–Yates did not simulate reality more finely; it simply saw the problem more precisely.

This trade-off is not confined to cards. Load analysis for a bridge must keep the material, the structure, the forces; an online prize draw need not simulate how the slips tumble in the box, only that every number has the same chance of being drawn. How much reality a model should keep is decided not by the number of details, but by which details actually change the answer.

The best model is not the one that keeps the most reality;
it is the one that has deleted nothing that matters.

Next time you see a computer fan a deck open, the screen may show cards flying and a crisp riffling sound. That is design, atmosphere, the metaphor we know.

What truly makes the game fair may be only those 51 steps in the background.

Sources and further reading

  1. Dave Bayer & Persi Diaconis, “Trailing the Dovetail Shuffle to Its Lair”, The Annals of Applied Probability, 1992.
  2. Robin Pemantle, “Randomization Time for the Overhand Shuffle”, Journal of Theoretical Probability, 1989.
  3. Ronald A. Fisher & Frank Yates, Statistical Tables for Biological, Agricultural and Medical Research, 1938.
  4. Evi Kordon, “The Fisher–Yates shuffle”, Archive of Formal Proofs, 2026.
From the lab

Enjoyed this?

Get new writing from the lab in your inbox, plus the occasional invite to a class. Free and paid tiers — read at your own depth.

Subscribe — free & paid
Keep reading
The Price Isn't Known Yet. The Money Arrives Anyway.
Finance 12 min
Some Sounds Disappear Without Being Noticed
Data × Behaviour 12 min
AI Prehistory | Two Legends Who Made Encoding Possible · Part II · Turing
AI 13 min
← All writing 海納百川,自乘一派