Seven shuffles, or eleven
A riffle is the ordinary shuffle: cut the deck in two, roughly in half, and let the cards fall from both thumbs so the halves interleave. How many riffles make a deck random has an exact answer, and it is seven for 52 cards — if “random” means what Dave Bayer and Persi Diaconis took it to mean in 1992. Ask for something stricter and it is eleven. Both numbers are worked out on this page from scratch, and so is the reason the first few riffles hardly count at all.
Riffle a deck
The cards are coloured by where they sat in the new deck, top card amber at the left and bottom card teal at the right; each row of the figure is the deck after one more shuffle. A riffle here is the model Gilbert and Shannon wrote down and Reeds worked out: the cut is where n coin tosses say, so it is near the middle and rarely exactly there, and each card drops from the left thumb or the right with a chance in proportion to how many that thumb still holds. It is a model of a hand, not a hand; a practised shuffler drops cards more evenly than this, and the perfectly even one is the last section of the page.
The page opens on four riffles drawn from a fixed seed, the first one tried rather than a picked one, so that every reader starts on the same deck and can see the same thing in it. Every press after that draws new ones.
Look along a row for the amber cards, then the violet, then the teal, and they are in order: a riffle keeps each half in its own order, so after one riffle the deck is two runs laced together. Card 1, card 2, card 3 and so on, reading down the deck, until the next card is higher up than the last one was — that is where one rising sequence ends and the next begins. A new deck has one. A riffle can at most double the count, so k riffles leave at most 2k, and a well-shuffled deck of 52 has about 26 and a half on average.
How far from random
Every order of the deck has a chance of coming out of k riffles, and remarkably it depends on one number only — how many rising sequences the order has. With r of them, it is
C(2k + n − r, n) ÷ 2kn
for a deck of n cards: the number of ways to choose n things from 2k + n − r, over 2kn. Fewer rising sequences means more likely, so a deck that has been shuffled a little is lopsided in a way you could bet on. How lopsided is the question, and there is more than one honest way to ask it.
Total variation is the edge of the best single bet. Choose any yes-or-no question about the order — any at all — and compare how often it comes out yes on the shuffled deck and on a fair one. The biggest difference any question can make is the distance. Bayer and Diaconis computed it for 52 cards and printed it in a table, and the page below works out the same table exactly rather than quoting it.
Separation asks the other way round: how far short of its fair chance does the least likely order fall? That order is always the one with the most rising sequences, which is the deck turned upside down, and riffles are very bad at producing it.
The dashed line is where the famous answer comes from, and it is a choice. A half is nobody’s law: it is a convenient place to read a steep curve, and it is the line the seven is read off. Move the line and the number moves with it — The page opens on 52 cards because a deck does.
Most of the deck is out of reach at first
After k riffles no order with more than 2k rising sequences can come up at all, and most orders of a big deck have a lot of them.
So for the first few riffles the distance is not merely large. After three it is one minus a number with twenty noughts after the point, because every order of the deck but that share is still impossible. The fall, when it comes, is steep, and Bayer and Diaconis called it the cutoff. Drag the slider and it keeps its shape while it moves; each time the deck doubles, the cutoff moves along by about one and a half riffles —
Why the chance is a count
Run a riffle backwards. Give every card in the shuffled deck a label, heads or tails, pull the heads out in order and put them on top of the tails: that undoes a riffle, and every way of labelling is equally likely. Two riffles backwards are two labels each, which is four kinds of label — two riffles are one riffle into four packets, and k riffles are one into 2k.
Now take an order with r rising sequences and ask how many labellings of a into packets produce it. Reading the cards from 1 to n, the labels can never go down, and they must go up at each of the r − 1 places where a rising sequence breaks. Count those and you are choosing n labels, in order, from a − r + 1 kinds with repeats allowed: C(a + n − r, n) of the an labellings. That is the whole formula, and the checks at the foot of the page count it by brute force for small decks instead of trusting this paragraph.
The perfect shuffle
A magician can cut exactly 26 and 26 and drop the cards one from each side, perfectly. There are two ways to do it: the out-shuffle keeps the top card on top, the in-shuffle tucks it in second. That is one riffle out of all of them, and it is the least random thing you can do to a deck: eight out-shuffles put 52 cards back exactly where they started. In the figure at the top, press it eight times.
The reason is arithmetic. Count the places from the top as 0 to 51. An out-shuffle moves the card in place i to place 2i, counted round a clock of 51, and leaves the bottom card where it is; so eight of them multiply by 28 = 256, which is one more than five times 51, and every card is home. An in-shuffle moves place i to 2i + 1 round a clock of 53, and you have to double 52 times round that clock to get from 1 back to 1.
And the two together steer. To send the top card to any place you like, write the number of cards that should end up above it in binary, and read the digits from the left: 1 is an in-shuffle, 0 an out. The dial opens on place 27, the first card of the bottom half; every other place works the same way.