The Impossible Shuffle

Home › The math behind the madness › How many shuffles?

How Many Shuffles Does It Take to Randomize a Deck?

Most people give a deck two or three quick shuffles and call it random. Mathematics politely disagrees.

The short answer

Seven riffle shuffles. In 1992, mathematicians Dave Bayer and Persi Diaconis showed that a 52-card deck stays clearly out of order through the first five riffle shuffles and only gets close to random around the seventh. Overhand shuffling is far slower: it takes thousands of shuffles to mix a deck as well.

The table that settled it

Bayer and Diaconis measured how far a riffle-shuffled deck is from perfectly random, using a yardstick called total variation distance: 1 means the deck is still easy to tell apart from a random one, 0 means it's indistinguishable. Here are the numbers for a 52-card deck (we recomputed them from their formula):

Riffle shufflesDistance from random
11.000Barely mixed
21.000
31.000
41.000Still easy to tell apart from random
50.924Order starts to break down
60.614
70.334Close to random: the "seven shuffles" rule
80.167
90.085
100.043Each extra shuffle roughly halves what is left

Nothing much happens for four shuffles, then the distance collapses. That sudden drop is known as the cutoff phenomenon, and it's why "seven" became the rule of thumb.

Why riffles work and overhand shuffles don't

A riffle shuffle cuts the deck in two and interleaves the halves, so every card can move a long way. After one riffle, though, the deck is made of just two "rising sequences": the cards from each half still appear in their old order relative to each other. Each riffle at most doubles the number of these sequences, and a well-mixed deck has around 26 of them. Magicians use leftover rising sequences for card tricks, which is a good reason to shuffle seven times before playing anyone who owns a top hat.

An overhand shuffle only slides small packets of cards from one hand to the other. Cards near each other tend to stay near each other, so it takes thousands of overhand shuffles to reach the same level of mixing. "Washing" the cards (smooshing them around on the table) also works well, if you keep at it for long enough.

How computers shuffle: Fisher–Yates

Computers don't riffle. The standard method is the Fisher–Yates shuffle: start at the last card, swap it with a randomly chosen card at or above it, move one card up, repeat. With a good random number generator, every one of the 52! orders is exactly equally likely, in one pass.

Two classic ways to get it wrong:

  • The naive swap. Swapping each card with any card in the deck (instead of only the ones not yet placed) looks fine but makes some orders more likely than others.
  • A tiny seed. To be able to produce every deck, the random source needs at least 226 bits, because 2226 is just above 52!. A generator seeded with 32 bits can only ever produce about 4.3 billion different decks, a fraction of roughly 5 × 10-59 of them all. That's how the online poker shuffle mentioned in our same-deck-twice article was cracked.

How The Impossible Shuffle shuffles

On The Impossible Shuffle, every shuffle is cooked from three public ingredients: the randomness of a drand round (published every 30 seconds by the League of Entropy, so nobody can know it in advance), the player's seat and a shuffle number. They go through SHA-256, and the 256-bit result drives Fisher–Yates. Since 2256 is far bigger than 52!, every deck is possible, and the leftover bias is about 1 in 1.4 billion: too small to ever notice.

Best of all, anyone can replay any shuffle and get the exact same deck. So if somebody ever does hit the Holy Grail, the whole world can check it.