# Card Shuffling Shenanigans

Shuffling cards is a tricky business. It's also a lucrative one for gambling casinos.

In a game such as blackjack, an astute player can try to memorize the cards already played to have a better chance of predicting which cards will come up later, thus potentially gaining an advantage over the dealer and the casino. If the cards aren't properly shuffled and their distribution isn't truly random, the advantage could be even greater.

Indeed, to keep games moving along at a brisk pace, blackjack dealers don't always take the time to perform the seven riffle shuffles necessary to achieve an adequate level of mixing (see Disorder in the Deck: Disorder in the Deck). This means that certain sets of cards may remain close enough together to be tracked through the deck, and players can use such vestiges of pattern to their profit.

To counter card tracking and dealer miscues, casinos introduced the use of multiple decks and mechanical card shufflers. Originally, these ingenious devices mimicked people, cutting the deck and interlacing cards to perform riffle shuffles. The action occurred inside a largely transparent box so players could see what was going on. A scam in which a team of gamblers used a hidden video camera to photograph a shuffle, analyzed the tape at much slower speeds to detect the card sequence, and transmitted the sequence information to players proved an expensive lesson on the disadvantages (to the casino) of such openness.

The newest shuffling machines, just coming on the market, are essentially black boxes. Moreover, they rely not on the physical randomness of interlacing cards (as in a riffle shuffle) but on computer-generated random numbers to determine card distribution.

Typically, an automated card shuffler pulls cards one by one from the bottom or top of a deck and slides each card into one of, say, 10 slots. A random number generator decides into which slot a given card goes. A second random number determines whether the card goes on the top or bottom of any cards already present in a slot. It never goes into the middle of a pile. Once the sorting of the cards into the slots is completed, a third set of random numbers decides the order in which the 10 piles of cards are assembled into the shuffled deck.

Does such a card shuffler truly randomize a deck? Statisticians Persi Diaconis and Susan Holmes of Stanford University recently had a chance to address that question when they were invited by the manufacturer of a prototype machine to check out how well it worked.

That there was a problem became evident immediately. Suppose you start with an ordered deck in which all the red cards are on top and all the black cards are on the bottom. If the shuffling machine takes cards from the top of the deck, red cards will get placed in the slots first, then black cards. Because a card never goes into the middle of a pile already in a slot, red and black cards will form a sandwich, with black cards always on the outside. Moreover, cards put on top of a pile in a given slot end up in the same order in which they were before the shuffle. Cards on the bottom of a pile end up in the opposite order of the original sequence.

With only 10 slots, the shuffled deck consists of 20 groups of cards that alternate between ascending and descending card orders. That's equivalent to labeling each card randomly with a number from 1 to 20, then collecting into piles the cards with the same number, taking care to reverse the order of even-numbered piles. This also demonstrates that the machine's final act of gathering up the piles in random order achieves nothing, Diaconis says. "That was a lot of engineering for no useful purpose."

Diaconis and Holmes figured out the precise probability that any given card would end up in any given location after one pass through the shuffling machine. Their data showed that the automated shuffler randomized the deck about as well as three riffle shuffles, well short of the seven riffle shuffles needed to get proper mixing.

These remnants of pattern in a machine-shuffled deck can be exploited by an alert gambler. Holmes worked out a simple game that demonstrated how this might work. The idea is to take cards from a shuffled deck, one by one, and try to predict which number will come next while keeping track of cards already seen. On the first card, a player has a 1 in 52 chance of being correct; on the next card, a 1 in 51 chance, and so on. He or she will certainly guess the identity of the last card and will guess the second-last card half the time. Overall, with a properly shuffled deck, a player would guess about four or five cards correctly.

Suppose the cards are initially numbered from 1 to 52 and start out in numerical order. After being put through a shuffling machine, the deck will have sequences of cards that alternate between ascending and descending values. Start by predicting that the highest possible card, 52, will be on top. If it turns out to be 49, predict 48 for the second card. Keep on going until your prediction is too low. For example, you predict 17, but the card is 20. This means that you have reached the end of a descending sequence, so the numbers will start climbing. So you should predict 21 for the next card. By applying this strategy, you can in the long run guess about 9 or 10 cards correctly. Such a shift in the odds could give a blackjack player an enormous advantage.

One way to improve the card-shuffling machine is to build it with 52 slots, but that alternative is probably too expensive for a manufacturer to implement. Perhaps a better solution is to feed cards through the machine twice, Diaconis suggests.

There may be more such problems to come, when engineers design and build new automated or computer-based systems without really understanding the mathematical underpinnings of their devices. Indeed, casinos and manufacturers of gambling equipment are already developing cardless systems in which dealers simply push buttons and images of cards appear on monitors in front of players. No physical cards are actually shuffled and dealt.

Casinos like these automated systems because they cut down on errors and cheating. No one can mark cards and memorize deck locations, and dealers and players can't help each other out. It's much harder to hide a virtual card up your sleeve. Best of all, the automated systems speed up play, all to the casino's advantage.

At the same time, these computer-based systems rely on the use of random number generators, which can have serious flaws. Indeed, no computer-based, formula-driven random number generator can be counted on as a reliable source of random numbers under all circumstances. Add in the sorts of software and hardware problems that inevitably plague modern computer systems, and you have a recipe for a different sort of randomness, where neither casinos nor players can really trust the results.