Random

Everyday randomness

Seven shuffles: how long it takes to mix a deck

A fresh deck is a rainbow. One riffle barely dents it. Watch the order break up shuffle by shuffle and see why “seven” is the famous number.

Skip to the experiment

By Stuck at Home, LLC ·

Open a new pack of cards and the order is perfect: ace to king, suit by suit. Now give it one riffle — split it in two, let the halves fall together — and look again.

It is still almost entirely in order. Two neat sequences, zipped. Anyone who has seen the first few cards could tell you roughly where the rest are. Riffle again and there are four sequences. Again, eight. The deck is being folded, not yet mixed.

So how many riffles does it take before the deck has genuinely forgotten where it started? Mathematicians have an answer, and card players usually stop well short of it.

After one riffle
1 ×Two rainbows,
zipped.
Not mixed. Folded.
An illustration of the idea.
The real deck is below.

Each bar is a card, coloured by where it started. Riffle and watch the rainbow come apart — and count how many shuffles it takes before you can’t see it any more.

A rainbow deck

Riffle until the colours forget.

Fifty-two cards, coloured from red (top of the new deck) through to violet (bottom). Each riffle splits the deck about in half and lets the halves fall together the way real hands do.

0Riffles so far
1Rising runs
51Neighbours still together

A new deck: one smooth rainbow.

A “rising run” is a stretch of cards still in their original order. A new deck has one; each riffle can at most double the count; a thoroughly mixed deck averages about 26. The shuffle follows the standard mathematical model of a human riffle, driven by the same Web Crypto source as the rest of the site.

What a riffle actually does.

Cut the deck roughly in half, then let the two halves drop together, a few cards from each side at a time. Nothing about that destroys order; it interleaves it. If the deck started as one rising run — 1, 2, 3 … 52 — a single riffle leaves two rising runs woven together. A second riffle leaves at most four, a third at most eight. The deck is being folded like dough, and dough takes a while to mix.

You can watch the folding in the rainbow above. After one riffle the colours are still clearly two gradients zipped together. After three you can still pick out stripes. Somewhere around five or six it starts to look like noise — and the “neighbours still together” count, which starts at 51, tumbles towards the handful you would expect from a genuinely random order.

Why seven.

In 1992 Dave Bayer and Persi Diaconis analysed the mathematics of the riffle and showed that about (3/2) × log2(n) shuffles are needed to mix n cards — for 52 cards, about seven. With fewer, the original order is still detectable to anyone who knows what to look for; with more, you gain almost nothing. The result made the New York Times under the headline “In Shuffling Cards, 7 Is Winning Number”.

“Mixed” is a matter of definition, and other definitions give other numbers. Measuring the information left in the deck instead, Lloyd Trefethen and his father argued that five riffles do a reasonable job and six make thorough mixing practically certain. Under a stricter yardstick the answer is eleven. Seven is the number that stuck because it answers the question most card players are asking: could an attentive opponent still exploit the order?

What the counters above mean

A rising run is a stretch of cards still in their original relative order — the fresh deck is one long run, and each riffle can at most double the count. A thoroughly mixed 52-card deck averages about 26 runs, which is where the counter settles after enough shuffles. “Neighbours still together” counts cards still sitting directly on the card they started on; in a random order you would expect roughly one. The shuffle in the demo follows the Gilbert–Shannon–Reeds model that Bayer and Diaconis studied: the cut is binomial, and each card drops from a packet with probability proportional to that packet’s size.

And please don’t overhand.

The casual shuffle most of us do — dribbling little packets from one hand into the other — is spectacularly bad at this. Diaconis and Jason Fulman put the number of overhand shuffles needed to mix a deck well at around ten thousand. Three overhands and a cut, which is what happens at most kitchen tables, leaves the deck very nearly in the order the last hand left it.

If that sounds like an abstract worry, consider the size of the space you are failing to explore. A deck of 52 cards can be arranged in 52! ways — about 8 × 1067, a number that makes the atoms in the Earth look sparse. A properly shuffled deck is almost certainly in an order that has never existed before. A badly shuffled one is a rerun.

For a list of names rather than cards, there is a shortcut to the fully mixed state: a computer can produce any one of those orderings with equal probability in a single step. That is what the shuffler below does, with no practice and no sore thumbs.

Where we looked things up