Thousands of mechanical mixers were in operation in Las Vegas, the United States, and the rest of the world. Rental rates were in the millions of dollars annually, and the company’s shares were traded on the New York Stock Exchange.
But the executives recently discovered that one of their devices had been “hacked” by a gang of freelancers. They used a video camera hidden behind a window to record the process of shuffling the cards.
The images, transmitted to a partner in the casino’s lobby, were shown in slow motion to determine the sequence of cards in the deck, which the players inside were informed. The casino lost millions of dollars until the gang was finally caught.
The executives were determined not to be hacked again and developed a prototype of a new, high-end card shuffler, this time encased in an opaque box.
Its engineers made sure the machine efficiently shuffles cards in just one pass through the machine, reducing the time for human manipulation of the deck and also making it difficult for card counters and fraudulent dealers.
But they needed to make sure their machines mixed the cards well. Therefore, they needed Percy Diaconis.
Diaconis, a magician who trained as a mathematician at Stanford University in the United States, is considered the world’s first expert in the mathematics of card shuffling. In all the scientific literature on the subject (which is surprisingly large), his name stands out as the ace of spades in a magic trick.
So when company executives called him and offered to show him the inner workings of the machine – the real “black box” – he hardly believed him.
Diaconis traveled with his assistant Susan Holmes, a Stanford statistician, to the company’s showroom in Las Vegas to inspect a prototype of the new machine. The duo soon discovered a flaw.
Although the mechanical shuffling procedure appeared to be random, mathematicians note that the result still contains ascending and descending sequences, meaning that predictions about the order of the cards can still be made.
To prove it to company executives, Diaconis and Holmes devised a simple technique for guessing the card that would be revealed next.
Suppose the first face-up card was five hearts. His guess would be that the next card would be the Six Hearts, imagining that the rectum was getting bigger. If the next card is actually lower – the four hearts, for example – then the straight is down and your next guess will be the three hearts.
Using this simple strategy, mathematicians can guess nine or 10 cards per suit – one-fifth of the total and enough to double or triple the advantage of a competent card counter.
Card counting is a practice in which a player keeps track of the cards that have been played, so as to have a slight advantage in predicting the probability that the next card will be good or bad.
This practice has been around for decades (and in some games, like bridge, it’s a legitimate part of the game), but it’s heavily suppressed in casino games, like blackjack or blackjack. It is illegal to use technology to assist the card counter.
Executives freaked out. They wrote to Diaconis: “We are not satisfied with your conclusions, but we believe them and that is why we appointed you.” The company silently stopped the prototype and turned its attention to another machine.
Diaconis has spent his life studying problems at the boundary between order and randomness – whether it’s decoding messages, putting together strands of DNA, or optimizing web search engines.
His interest in letters began in a meeting by chance in 1958. At the age of 13, at a traditional Tannen’s Magic Emporium, in Times Square, New York (US), Diaconis met Alex Elmsley, a Scottish-speaking magician and computer scientist. Quiet, who mastered the “perfect mixing”.
Sometimes called a “pharaoh’s deck” or simply “technique,” the ideal shuffle consists of chopping a deck of cards into two suits of exactly 26 cards each and shuffling the cards just like a cloud, alternating one card from each hand.
Very few people manage to do it right in less than 10 seconds. The deacon is one of them.
Perfect shuffle has been used by players and magicians for centuries because it gives the illusion that cards are shuffled randomly. But it’s far from truly random. If you perform the same sequence of perfect shuffles eight times in a row, the deck will magically return to its original order.
Diaconis likes to show off the perfect mix by taking a new deck and writing the word “RANDOM” on one side of the cards with a black marker.
As he does his trick with the cards, the letters blend together. Sometimes they appear in a ghostly form, like a poorly set image on an old TV.
But after mixing it up for the eighth and final time, the word reincarnates next to the deck. The cards are exactly in their original sequence.
Back at the Magic Emporium in Tannen, Elmsley explained the exact math behind the trick. Imagine that you are numbering a new deck from 1 to 52, where 1 is the top card in the deck and 52 is the bottom card.
Markov chain, a powerful mathematical tool, is behind the success of card counting and casino multiplication – Image: Getty Images via BBC
When you make a perfect shuffle, the cards move to new positions in the deck. A card that was originally in position 2, for example, will move to position 3; The card in position 3 will move to position 5… The card in position 27 will go back to position 2 and so on.
An ideal mixing can be considered a whole series of courses, like musical chairs in separate games. The number of times it takes the cards to return to their correct order is the LCM of the extensions of all the turns: in this case, eight (since 8 is the LCM of 1, 2, and 8).
A year after meeting Elmsley at the Magic Emporium in Tannen, Diaconis left home at the age of 14 to learn magic under the supervision of a famous magician. They have spent 10 years on the road, learning every possible technique of shuffling cards and watching rogue dealers learn their techniques.
But the conversation with Elmsley piqued Diacones’ curiosity. What other connections can be between mathematics and magic?
Diaconis claims that his tomb will be inscribed with the words “A stampede of seven is enough.” He points to his most famous discovery: it takes seven “quick dodges” to create a random enough surface.
Quick shuffling is a familiar technique, used in casinos and by serious card players, in which cards are cut in two and cards pushed with the thumbs so that they interlock satisfactorily, often ending in a bridge that links the cards together with letters arranging a pile.
Quick Mix is the twin brother of the perfect mixing. Instead of smoothly permeating the two halves of a deck, the two halves are shuffled together in disorganized combinations, planting a random seed that gradually shuffles the cards each time they are shuffled.
After a quick shuffle or two, some cards will remain in their original sequence. Even after four or five random shuffles (more than usual in most casinos), the deck will retain some trace of the system. But when you shuffle seven times, the cards really do shuffle, at least in most statistical tests.
After this point, no more blending will produce great results. According to Diaconis: “It’s as close to random as possible.”
To study the scramble accurately, Diaconis used a mathematical tool known as a Markov chain.
Mathematician Sami Hayes Assaf, from the University of Southern California in the US, explains that “a Markov chain is any repeated action whose outcome depends only on the current state and not on how that state was arrived at.”
This means that Markov chains have no “memory” of what happened before. It’s a very good model for shuffling the cards, according to Assaf. The result of the seventh switch depends only on the cards after the sixth deal and not on how the deck has changed in the previous five times.
Markov chains are widely used in statistics and computer science to handle random sequences of events, whether it’s switching cards, shaking atoms, or fluctuations in stock prices. In each case, the future “state” – the order of the cards, the energy of the atom, or the value of the action – depends only on what is happening now, not on what happened before.
Despite their simplicity, Markov chains can be used to make predictions about the probability of certain events occurring after several iterations. Google’s PageRank algorithm rates websites in their search results based on the Markov chain, which models the behavior of billions of Internet users who randomly click on links on the web.
Working with mathematician Dave Baer, of Columbia University in New York, in the US, Diaconis showed that a Markov chain describing a rapid scramble shows a strong transition from ordered to random after seven scrambles. This behavior, known to mathematicians as the discontinuity phenomenon, is a common feature of problems involving mixtures.
Imagine that you are stirring cream into coffee. While stirring, the cream forms thin white streaks in the black coffee, until blended suddenly and irreversibly.
Knowing which side of the deck is on – whether it’s mixed well or whether it still retains some memory from the original arrangement – gives players a clear advantage against the bank.
In the 1990s, a group of students from Harvard and MIT (Massachusetts Institute of Technology, USA) managed to beat the odds by playing blackjack in casinos in different parts of the United States, counting cards and using other methods to verify that the deck was Mixed well.
Casinos responded by introducing more complex shuffling machines and random shuffles before the cards were fully entered into the game, as well as ramping up player monitoring. But it is still rare to see the cards being shuffled by the machines the seven times required in the casino.
Casino managers may not have paid much attention to Diaconis and his research, but he still has a tremendous influence on mathematicians, statisticians, and computer scientists who study randomness.
At a conference at Stanford in January 2020 to celebrate Diaconis’ 75th birthday, colleagues from around the world gave lectures on topics such as the mathematics of genetic sorting, how pills settle into a box when shaken, and of course shuffling cards. .
Deacon is not much interested in games. He says there are better and more interesting ways to make a living. But he doesn’t resent players trying to exploit their brains.
“Thinking is not cheating,” he says. “Thinking is thinking.”
Shane Keating is a science writer and Professor of Mathematics and Oceanography at the University of New South Wales in Sydney, Australia.
“Wannabe internet buff. Future teen idol. Hardcore zombie guru. Gamer. Avid creator. Entrepreneur. Bacon ninja.”