# How fair is an almost perfect riffle shuffle?

I've been practicing an in-hands riffle shuffle, just to make it look and sound smooth. In doing so, I've noticed I'm able to weave the cards almost perfectly.

An almost perfect shuffle.

Is such an almost perfect shuffle, repeated a reasonable number of times, less fair than one with a higher proportion of imperfections?

# Note

The question is about almost perfect shuffles. Obviously a perfect shuffle does not randomize the deck at all, as anyone who has seen a magician do a faro shuffle knows.

Simply observing an almost perfect shuffle randomizes the cards less is not an answer. The premise of the question implicitly states that. How much does an almost perfect riffle shuffle randomize or not randomize the deck? Do eight almost perfect riffle shuffles mostly not reorder the deck, with perhaps a dozen cards out of order? Or do the errors compound with each shuffle such that it's really impossible to shuffle unfairly if the shuffle is done N times? How big must N be?

Please, no speculation or guessing. Cite sources, or show some math.

• There is a respectable body of academic discussion on this; this answer is a good place to start. – Tim Lymington Jan 27 '18 at 17:18

# An almost perfect riffle shuffle of a 52 card deck is not perfectly random, but should be sufficiently fair for any casual purpose.

I decided to test this experimentally. I coded up a quick python function* to perform riffles and almost perfect riffles.

When performing a perfect riffle, the code takes a "deck" of integers and rearranges them so that the first half and second half are interlaced, so the deck

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]

becomes

[26, 0, 27, 1, 28, 2, 29, 3, 30, 4, 31, 5, 32, 6, 33, 7, 34, 8, 35, 9, 36, 10, 37, 11, 38, 12, 39, 13, 40, 14, 41, 15, 42, 16, 43, 17, 44, 18, 45, 19, 46, 20, 47, 21, 48, 22, 49, 23, 50, 24, 51, 25]

For an imperfect riffle, the function adds a defect where two numbers are kept together without an intervening one from the other half. For example, the 0-51 range might instead become

[26, 0, 27, 1, 28, 2, 29, 3, 30, 4, 31, 5, 32, 6, 33, 7, 34, 8, 35, 9, 36, 10, 37, 11, 38, 12, 39, 13, 40, 14, 41, 15, 42, 16, 43, 17, 44, 18, 45, 19, 46, 20, 47, 21, 22, 48, 23, 49, 24, 50, 25, 51]

The defect is added at a random point during the interlacing.

Repeating the perfect riffle shuffle on a 52 card deck 7 times generates a very regular pattern:

[40, 28, 16, 4, 45, 33, 21, 9, 50, 38, 26, 14, 2, 43, 31, 19, 7, 48, 36, 24, 12, 0, 41, 29, 17, 5, 46, 34, 22, 10, 51, 39, 27, 15, 3, 44, 32, 20, 8, 49, 37, 25, 13, 1, 42, 30, 18, 6, 47, 35, 23, 11]

The imperfect shuffle on the other hand, generates a unique pattern every time. One example was

[31, 0, 38, 51, 26, 8, 44, 29, 14, 36, 2, 20, 3, 5, 27, 46, 24, 33, 32, 17, 40, 25, 10, 22, 48, 30, 35, 1, 50, 42, 7, 12, 45, 13, 39, 37, 19, 43, 4, 18, 28, 34, 15, 23, 16, 41, 6, 11, 21, 49, 9, 47]

That looks pretty random. Is it, though? I decided to Monte Carlo it, and "shuffled" the deck 100,000 times to look at how the numbers distributed.

It turns out that this is not nearly as random as it appears. In a perfectly random shuffle each number should have a 1/52 chance (1.92%) of appearing in any position. But my results were instead that the probabilities ranged from 0.02% to 18.5%. That's a great deal more likely than 1.92%.

But while it's not good that card 10 is ending up in slot 26** 18% of the time, it's not something that is easy to abuse either. Did you know what card #10 was? Do you care what card #26 is? Your goal is not a random deck, but instead a fair one. That means that a bit of unrandomness is fine, as long as no players are taking advantage of it. 7 almost perfect shuffles leaves patterns that could be taken advantage of, but they are sufficiently complex enough that you would have to dedicate significant time and energy to do so.

And it's easy to add extra randomness by cutting the deck or throwing in a few extra shuffles. Furthermore, I've almost certainly underestimated the amount of randomness, since the "almost perfect riffle" pictured in the OP has 3 defects instead of 1, and shufflers will not always perfectly divide the deck in half like I assumed.

All told, I do not think that you need to worry about your excellent riffling skills disrupting your card games. But perhaps be careful if you play with professional card counters.

*I can share the code if anyone's interested, but it isn't really relevant.

**Or possibly the other way around. I get my axes confused sometimes.

A perfect riffle shuffle is not very effective at randomizing the cards. Cards from one half of the deck are (perfectly?) interleaved with those from the other, not changing the order of any cards relative their previous neighbors, but only leaving zero or more cards (one, in a perfect shuffle of a perfectly cut deck) from the other half between them.

There are other shuffles that randomize much better (though a proper "52 pick-up" is too slow for most card players and has the hazard of "misplacing" cards). A riffle shuffle looks and sounds nice, however, lends itself to the "bridge" square-up afterward, and can be easily undone by a card manipulator (which, along with its appearance and sound, is why it's popular with card magicians).

• This doesn't really answer the question, which is about almost perfect riffle shuffles. – Phil Frost Jan 26 '18 at 20:45
• Also a fair riffle shuffle does an excellent job of randomizing the cards if it's done at least seven times: dartmouth.edu/~chance/course/topics/winning_number.html – Phil Frost Jan 26 '18 at 20:46
• What do you mean by "almost perfect?" – The Chaz 2.0 Jan 26 '18 at 23:44
• @TheChaz2.0 It's explained in the question. – Phil Frost Jan 26 '18 at 23:50
• Right. Then what do you mean by "usually?" – The Chaz 2.0 Jan 27 '18 at 0:04

The point of a shuffle is to eliminate knowledge of the order in the deck.

A perfect riffle shuffle (one which follows a left-right-left-right-... pattern) does not eliminate any knowledge. It is possible to determine, from the initial state, the exact position of all cards after a perfect riffle.

To eliminate the knowledge, we need to introduce randomness. For a riffle this means not knowing from which side the next card will come, supposing we knew which side the last card came from. Such a riffle can provide effective randomisation after seven riffles.

Obviously, if you know more about which card comes next, you know more about where each card ends up. The closer to a perfect riffle you make, the closer to the original order you're likely to have. For example, if only two "errors" (instances of breaking the perfect riffle pattern) are made, you can expect at most four cards to be out of place from the order expected in a perfect riffle. More "errors" push you closer to the point of a random riffle, but interestingly, a 100% error rate is equivalent in knowledge to a 0% error rate. Being as close to 50% wrong as possible provides the best randomisation, and this is equivalent to the statement made previously (we need to know as little as possible as which side the next card comes from).

Thus, an almost-perfect riffle will not disorder the deck as much as a shuffle that includes many more errors, but will be no worse than one which has almost all possible errors.

However that considers only a single riffle. This is not practically the case in real shuffling of game decks where we use many repetitions. Assuming we don't know where the errors will be, having fewer errors simply means we need more shuffles to ensure every card has had an opportunity to be exposed to at least one error. By knowing every card may be in error, and not knowing the order of those errors, we reduce the knowledge of the order until it reaches the same as that of random guessing.

For a random riffle, this is approximately seven repetitions. For an almost-perfect shuffle, it's probably in the multiple hundreds.

• Do you have a reference for "probably in the multiple hundreds"? – Phil Frost Jan 27 '18 at 0:23
• @PhilFrost: The number of shuffles required would depend on how "almost" perfect the shuffle is. If there's an average of one "slip" per shuffle and it's uniformly randomly distributed, then about 50 shuffles should probably suffice, but if the slips aren't uniformly randomly distributed some cards might never get mixed in. – supercat Jan 27 '18 at 1:09
• I tried finding the paper where this was simulated, but don't remember the title and GScholar keeps bringing up others. If it's one expected error per riffle, definitely well into three digits. It has a decline to somewhere in two digits if there's a dozen expected errors, and then approaches single digits as you hit an expected rate of errors of half the riffles (i.e. when you can't tell approximately whether this card will or will not be an error). – Nij Jan 27 '18 at 1:19