A riffle cuts the deck about in half and interleaves the two packets. The packets are still visible afterwards as rising sequences — runs of cards whose original order survived. Each colour below is one rising sequence. One riffle can leave at most two, two riffles at most four, and that ceiling is exactly what makes the deck guessable.
The deck is generated by the Gilbert–Shannon–Reeds model: cut k cards off
the top with probability C(52,k)/2^52, then drop the next card from whichever packet
still holds more, with probability proportional to its size. Everything is seeded, so the same seed
always deals the same deck.
Bayer and Diaconis put the question this way. A deck lies face down. You guess the top card; it is turned over and discarded; you guess again. On a genuinely random deck the best anyone can do is 4.54 cards right out of 52. On a deck that has only been riffled a few times you will do very much better — and how much better is a concrete, unarguable measure of how far from random it still is.
Press Deal to shuffle a deck and start guessing.
Turned over
Table 5 of the paper, and this page's own run of it
Each published cell is an average over 100,000 trials of the same strategy. The column beside it is this bundle's own Monte Carlo, run by the build harness with the interval printed. The strategy is only conjectured to be optimal — the paper says so.
| shuffles | published | this build | 95% interval | ahead of random |
|---|
The distance between a shuffled deck and a random one does not drift down. It sits pinned at its maximum, then falls off a cliff. That is the cutoff phenomenon, and the riffle shuffle is its cleanest example — because Bayer and Diaconis found a closed form for the chance of every one of the 8×1067 arrangements, the curve below is computed exactly, not sampled.
Solid: total variation distance, computed here from the closed form. Rings: the values printed in Table 3 of Bayer & Diaconis (1992). Dashed: the separation distance, a stricter metric that asks whether any single arrangement is still short-changed.
Table 3, recomputed
The same process, measured as information
A shuffled deck still holds information about the order it started in. Trefethen and Trefethen (2000) measured exactly that, in bits, and found no cutoff at all: the first shuffles each destroy about 52 bits, and after that every shuffle removes three quarters of whatever is left. The cliff in the chart above is a property of the metric, not of the shuffling.
“A few good shuffles randomises a deck.” The famous number attached to that sentence is seven. Seven is the first shuffle count at which the total variation distance for 52 cards falls below one half — a threshold picked because it makes a headline, not because the mathematics prefers it. Change the question and the number changes with it.
The bounded regime
| the question | what counts as randomised | shuffles |
|---|
Where one named card ends up
The gentlest question on that list. Follow a single card — say the one that started on top — and ask only where it is now. Its position mixes far faster than the whole arrangement does, because a marginal can never be further from uniform than the thing it is a marginal of.
After one riffle the original top card is still on top half the time, one down a quarter of the time, two down an eighth — it has barely moved. The bars flatten onto 1/52 long before the deck as a whole is anywhere near random.
The control: a shuffle that needs 151
None of this is a fact about decks; it is a fact about the riffle. Take the top card and slide it back in at a random place, and repeat. That is the top-to-random shuffle, and the same machinery — the same definition of distance, the same exact-enumeration check — says it needs 151 repetitions to get the total variation below one half, against the riffle's seven. Aldous and Diaconis proved its mixing time grows like n log n, which for 52 cards is 205.5; the exact finite-deck crossing sits below that, and closes on it as the deck grows.
Exact mixing times against the published asymptotics
| deck | riffle, exact | (3/2)log2 n | ratio | top-to-random, exact | n ln n | ratio |
|---|
Both ratios climb towards 1 as the deck grows. That is what it looks like when a finite deck is still some way short of the asymptotic regime a theorem describes — and it is why the exact answer for 52 cards is seven, not the 8.55 the formula gives.
What this is
An independent reimplementation of the mathematics in Dave Bayer and Persi Diaconis, “Trailing the Dovetail Shuffle to its Lair”, The Annals of Applied Probability 2(2), 1992, pages 294–313, together with the alternative measurement in L. N. Trefethen and L. M. Trefethen, “How many shuffles to randomize a deck of cards?”, Proceedings of the Royal Society A 456(2002), 2000, pages 2561–2568. The shuffle model itself is due to Edgar Gilbert and Claude Shannon (Bell Laboratories technical memorandum, 1955) and independently to Jim Reeds (1981). Rising sequences, the invariant the whole analysis turns on, were found by the magicians C. O. Williams (1912) and Charles T. Jordan (1916, 1919).
Not affiliated with, endorsed by or derived from the code of any of the above. Every formula here was implemented from the printed statement and then checked against a brute-force enumeration that shares none of its reasoning. The papers are cited, not copied; no text, figure or table image from either paper is reproduced in this bundle — only the numeric values, which are facts.
What is faithful, and what is mine
- Faithful. The GSR shuffle model. Theorem 1's closed form. The total variation convention. Table 1, Table 3 and Table 4 of the 1992 paper, to every printed decimal. Table 5's guessing game and its strategy. The entropy figures of the 2000 paper.
- Mine. The exact law of the top-to-random shuffle used for the control — the papers give only an asymptotic — together with the observation that its separation distance is the survival function of the second-from-bottom card's departure, one geometric step sharper than the usual coupon-collector bound. The bounded-regime table. All of the code.
- Different from the papers. Table 5 here is re-run at 20,000 trials per cell rather than 100,000, and its interval is printed. The cut-deck row is reproduced for six or more shuffles but not for one or two: the cut-adapted strategy is described only in prose and my reconstruction of it turns out to be slightly stronger than the one that produced the published row. That is reported rather than tuned away.
Check it yourself
The claim that the closed form is right is checkable here, now, in this tab. The button below builds the whole distribution over every arrangement of a small deck by brute force — cutting and interleaving, with integer counts over a common denominator, no formula anywhere — and compares every single arrangement against what Theorem 1 predicts.
Not run yet.
Credits and licence
Full credits in CREDITS.txt; the code is released under the MIT licence in LICENSE.txt. This page runs entirely in your browser: there is no account, no server call, no tracking and no model behind it.