All Topics  
Shuffle

 
Shuffle

   Email Print
   Bookmark   Link






 

Shuffle



 
 
Shuffling is a procedure used to randomize
Randomization

Randomization is the process of making something random; this means:* Generating a random permutation of a sequence .* Selecting a random sample of a population ....
 a deck of playing card
Playing card

A playing card is a piece of specially prepared heavy paper, thin card, or thin plastic, figured with distinguishing motifs and used as one of a set for playing card games....
s to provide an element of chance in card game
Card game

A card game is any game using playing cards as the primary things with which the game is played, be they traditional or game-specific. Countless card games exist, including families of related games ....
s. Shuffling is often followed by a cut
Cut (cards)

After a deck of cards is shuffled by the dealer, it is often given to a player other than the one who performed the shuffle for a procedure called a cut....
, to ensure that the shuffler has not manipulated the outcome.

A typical sequence between hands of poker
Poker

Poker is a family of card game that share betting rules and usually List of poker hands. Poker games differ in how the cards are dealt, how hands may be formed, whether the high or low hand wins the pot in a showdown , limits on bets and how many rounds of betting are allowed....
, for example, is a wash, two riffles, a strip, a third riffle, and a cut.

ral techniques are used to shuffle a deck of cards.






Discussion
Ask a question about 'Shuffle'
Start a new discussion about 'Shuffle'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Riffle Shuffle
Shuffling is a procedure used to randomize
Randomization

Randomization is the process of making something random; this means:* Generating a random permutation of a sequence .* Selecting a random sample of a population ....
 a deck of playing card
Playing card

A playing card is a piece of specially prepared heavy paper, thin card, or thin plastic, figured with distinguishing motifs and used as one of a set for playing card games....
s to provide an element of chance in card game
Card game

A card game is any game using playing cards as the primary things with which the game is played, be they traditional or game-specific. Countless card games exist, including families of related games ....
s. Shuffling is often followed by a cut
Cut (cards)

After a deck of cards is shuffled by the dealer, it is often given to a player other than the one who performed the shuffle for a procedure called a cut....
, to ensure that the shuffler has not manipulated the outcome.

A typical sequence between hands of poker
Poker

Poker is a family of card game that share betting rules and usually List of poker hands. Poker games differ in how the cards are dealt, how hands may be formed, whether the high or low hand wins the pot in a showdown , limits on bets and how many rounds of betting are allowed....
, for example, is a wash, two riffles, a strip, a third riffle, and a cut.

Shuffling techniques

Several techniques are used to shuffle a deck of cards. Some techniques are easy to learn while others achieve better randomization or are better suited to special decks.

Riffle

A common shuffling technique is called the riffle or dovetail shuffle, in which half of the deck is held in each hand with the thumbs inward, then cards are released by the thumbs so that they fall to the table interleaved. Many also lift the cards up after a riffle, forming what is called a bridge which puts the cards back into place. This can also be done by placing the halves flat on the table with their rear corners touching, then lifting the back edges with the thumbs while pushing the halves together. While this method is more difficult, it is often used in casino
Casino

A casino is, in the modern sense of the word, a facility that houses and accommodates certain types of gambling activities. Casinos are most commonly built near or combined with hotels, restaurants, retail shopping, cruise ships and other tourist attractions....
s because it minimizes the risk of exposing cards during the shuffle.

Stripping or overhand

Another procedure is called stripping, overhand, or slide shuffle, where small groups of cards are removed from the top or bottom of a deck and replaced on the opposite side (or just assembled on the table in reverse order).

Hindu shuffle

Also known as "Kattar" or "Kenchi" (Hindi for scissor). The deck is held face down, with the middle finger on one long edge and the thumb on the other on the bottom half of the deck. The other hand draws off a packet from the bottom of the deck. This packet is allowed to drop into the palm, then put on top of the first half. The maneuver is repeated over and over until the deck is all in the second hand. Hindu shuffle differs from stripping in that all the action is in the hand taking the cards, whereas in stripping, the action is performed by the hand with the original deck, giving the cards to the resulting pile. This is the most common shuffling technique in Asia and other parts of the world.

Pile shuffle

Cards are simply dealt out into a number of piles, then the piles are stacked on top of each other. This ensures that cards that were next to each other are now separated. The pile shuffle does not provide a good randomization of the cards (but this can be enormously improved by dealing to the piles in a different order each circuit, not always in the same order). It is sometimes used in collectible card games where other forms of shuffling can be damaging to rare cards.

Corgi, Chemmy or Wash shuffle

Also known as the Wash or Corgi, scramble or beginner shuffle this involves simply spreading the cards out face down, and sliding them around and over each other with one's hands. Then the cards are moved into one pile so that they begin to intertwine and are then arranged back into a stack. This method is useful for beginners and small children or if one is inept at shuffling cards. However, the beginner shuffle requires a large surface for spreading out the cards and takes longer than the other methods. The now often used name Corgi, originated in Yorkshire, England. It has spread and is used in many parts of the UK, and often heard in international poker rooms or tournaments such as the WSOP or EPT. It is quite common in casino poker rooms for dealers to use this method upon introducing a brand new deck, which are packaged in ranked order by suits, before shuffling it by some other means (i.e., a riffle shuffle or shuffling machine).

Mongean shuffle

The Mongean shuffle, or Monge's shuffle, is performed as follows (by a right-handed person): Start with the unshuffled deck in the left hand and transfer the top card to the right. Then repeatedly take the top card from the left hand and transfer it to the right, putting the second card at the top of the new deck, the third at the bottom, the fourth at the top, the fifth at the bottom, etc. The result, if one started with cards numbered consecutively , would be a deck with the cards in the following order: .

For a deck of given size, the number of Mongean shuffles that it takes to return a deck to starting position, is known .

Weave and Faro shuffles

Weaving is the procedure of pushing the ends of two halves of a deck against each other in such a way that they naturally intertwine. Sometimes the deck is split into equal halves of 26 cards which are then pushed together in a certain way so as to make them perfectly interweave. This is known as a Faro Shuffle

The faro shuffle
Faro shuffle

The faro shuffle is a method of shuffling playing cards.In a perfect shuffle or perfect faro shuffle, the deck is split into equal halves of 26 cards which are then pushed together in a certain way so as to make them perfectly interweave....
 is performed by cutting the deck into two, preferably equal, packs in both hands as follows (right-handed): The cards are held from above in the right and from below in the left hand. Separation of the deck is done simply lifting up half the cards with the right hand thumb slightly and pushing the left hand's packet forward away from the right hand. The two packets are often crossed and slammed into each other as to align them. They are then pushed together by the short sides and bent (either up or down). The cards will then alternately fall into each other, much like a zipper
Zipper

A zipper is a popular device for temporarily joining two edges of textile. It is used in clothing , luggage and other bags, sporting goods, camping gear , and other daily use items....
. A flourish can be added by springing the packets together by applying pressure and bending them from above. The faro is a controlled shuffle which does not randomize a deck.

A perfect faro shuffle, where the cards are perfectly alternated, is considered one of the most difficult sleights by card magicians, simply because it requires the shuffler to be able to cut the deck into two equal packets and apply just about the right pressure when pushing the cards into each other. If one does perform eight perfect faro shuffles in a row, the order of the deck will return to the original order, if there are 52 cards in the deck and if the original top and bottom cards remain in their positions (1st and 52nd) during the eight shuffles. If the top and bottom cards get weaved in during each shuffle then it takes 52 shuffles to return a deck back into original order (26 shuffles to reverse the order of a deck containing 52 cards).

False shuffles

Magicians, sleight-of-hand artists, and card cheats
Card sharp

A card sharp is a person who uses skill and deception to win at poker or other card games. Such a person is also known in card gaming jargon as a "mechanic"; an older Political correctness term is "greek"....
 employ various methods of shuffling whereby the deck appears to have been shuffled fairly, when in reality one or more cards (up to and including the entire deck) stays in the same position. It is also possible, though generally considered very difficult, to "stack the deck" (place cards into a desirable order) by means of one or more riffle shuffles; this is called "riffle stacking".

Both performance magicians and card sharps regard the Zarrow shuffle
Zarrow shuffle

Zarrow shuffle is a sleight of hand technique that gives the appearance of being a normal riffle shuffle, but in fact leaves the cards in exactly the same order....
 as a particularly effective example of the false shuffle. In this shuffle, the entire deck remains in its original order, although spectators think they see an honest riffle shuffle.

Shuffling machines

Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casino
Casino

A casino is, in the modern sense of the word, a facility that houses and accommodates certain types of gambling activities. Casinos are most commonly built near or combined with hotels, restaurants, retail shopping, cruise ships and other tourist attractions....
s employ automatic shuffling machine
Shuffling machine

A shuffling machine is a machine for randomly shuffling packs of playing cards.Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines to shuffle the cards before dealing....
s. They also save time that would otherwise be spent shuffling, allowing several more hands per hour to be played (increasing the profitability of the table). These machines are also used to lessen repetitive motion stress injuries to a dealer. Note that the shuffling machines have to be carefully designed, as they can generate biased shuffles otherwise: the most recent shuffling machines are computer-controlled, though they have not yet fully been integrated into gaming.

Randomization

There are exactly 52!
Factorial

In mathematics, the factorial of a negative and non-negative numbers integer n, denoted by n!, is the Product of all positive integers less than or equal to n....
 (about 8) possible ways to order the cards in a 52-card deck. The magnitude of this number
Orders of magnitude (numbers)

This list compares various sizes of positive numbers, including counts of things, dimensionless quantity and probability. Each number is given a name in the so called Long and short scales which is used in English speaking countries, as well as a name in the Long and short scales which is used in a series of countries that do not have English as th...
 means that it is exceedingly improbable that two randomly selected, truly randomized decks, will ever, in the history of cards, be the same. However, while the exact sequence of all cards in a randomized deck is unpredictable, it may be possible to make some probabilistic predictions about a deck that is not sufficiently randomized.

A famous paper by mathematician
Mathematician

A mathematician is a person whose primary area of study and/or research is the field of mathematics....
 and magician Persi Diaconis
Persi Diaconis

Persi Warren Diaconis is an United States mathematician and former professional Magic . He is the Mary V. Sunseri Professor of Statistics and Mathematics at Stanford University....
 on the number of shuffles needed to randomize a deck, concluded that the deck did not start to become random until five good riffle shuffles, and was truly random after seven, in the precise sense of variation distance described in Markov chain mixing time
Markov chain mixing time

In mathematical probability, a fundamental result about Markov chains is that a finite state irreducible aperiodic chain has a unique stationary distribution π and, regardless of the initial state, the time-t distribution of the chain converges to π as t tends to infinity....
; of course, you would need more shuffles if your shuffling technique is poor. Recently, the work of Trefethen et al. has questioned some of Diaconis' results, concluding that six shuffles are enough. The difference hinges on how each measured the randomness of the deck. Diaconis used a very sensitive test of randomness, and therefore needed to shuffle more. Even more sensitive measures exist and the question of what measure is best for specific card games is still open. Diaconis released a response indicating that you only need four shuffles for un-suited games such as blackjack
Blackjack

Blackjack is the most widely played casino game banking game in the world. Much of blackjack's popularity is due to the mix of chance with elements of skill, and the publicity that surrounds card counting ....
 .

One sensitive test for randomness uses a standard deck without the joker
Joker (playing card)

The Joker is a special card found in most modern decks of playing cards, or a Mahjong tiles in some Mahjong game sets....
s divided into suits with two suits in ascending order from ace to king, and the other two suits in reverse. (Many decks already come ordered this way when new.) After shuffling, the measure of randomness is the number of rising sequences that are left in each suit.

In practice the number of shuffles that you need depends both on how good you are at shuffling, and how good the people playing are at noticing and using non-randomness. Two to four shuffles is good enough for casual play. But in club play, good bridge players take advantage of non-randomness after four shuffles, and top blackjack
Blackjack

Blackjack is the most widely played casino game banking game in the world. Much of blackjack's popularity is due to the mix of chance with elements of skill, and the publicity that surrounds card counting ....
 players supposedly track aces through the deck; this is known as "ace tracking", or more generally, as "shuffle tracking".

Shuffling algorithms


In a computer, shuffling is equivalent to generating a random permutation
Random permutation

A random permutation is a random ordering of a set of objects, that is, a permutation-valued random variable. The use of random permutations is often fundamental to fields that use randomized algorithms....
 of the cards. There are two basic algorithms for doing this, both popularized by Donald Knuth
Donald Knuth

Donald Ervin Knuth is a renowned computer science and Emeritus of the Art of Computer Programming at Stanford University.Author of the seminal multi-volume work The Art of Computer Programming , Knuth has been called the "father" of the run-time analysis, contributing to the development of, and systematizing formal mathematical techn...
. The first is simply to assign a random number to each card, and then to sort the cards in order of their random numbers. This will generate a random permutation, unless two of the random numbers generated are the same. This can be eliminated either by retrying these cases, or reduced to an arbitrarily low probability by choosing a sufficiently wide range of random number choices.

The second, generally known as the Knuth shuffle or Fisher-Yates shuffle
Fisher-Yates shuffle

The Fisher-Yates shuffle, named after Ronald Fisher and Frank Yates, also known as the Knuth shuffle, after Donald Knuth, is an algorithm for generating a random permutation of a finite set?in plain terms, for randomly shuffling the set....
, is a linear-time
Linear time

In computational complexity theory, an algorithm is said to take linear time, or Big O notation time, if the asymptotic upper bound for the time it requires is proportional to the size of the input, which is usually denoted n....
 algorithm (as opposed to the previous O
Big O notation

In mathematics, big O notation describes the asymptotic analysis of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions....
(n log n) algorithm if using efficient sorting such as mergesort or heapsort
Heapsort

Heapsort is a comparison sort sorting algorithm, and is part of the selection sort family. Although somewhat slower in practice on most machines than a good implementation of quicksort, it has the advantage of a worst-case big O notation runtime....
) which involves moving through the pack from top to bottom, swapping each card in turn with another card from a random position in the part of the pack that has not yet been passed through (including itself). Providing that the random numbers are unbiased, this will always generate a random permutation.

Implementation

For a variety of reasons, shuffling algorithms can be particularly difficult to implement. Here are some of the most common pitfalls:

Poorly implemented Knuth shuffles
Care needs to be taken in implementing the Knuth shuffle; even slight deviations from the correct algorithm will produce biased shuffles. For example, working your way through the pack swapping each card in turn with a random card from any part of the pack is an algorithm with nn different possible execution paths, yet there are only n! permutations, and a counting argument based on using the pigeonhole principle
Pigeonhole principle

In mathematics, the pigeonhole principle, also known as Dirichlet's box principle, is exemplified by such things as the fact that in a family of three children there must be at least two of the same gender....
 on assignments of execution paths to outcomes shows that this algorithm cannot produce an unbiased shuffle, unlike the true Knuth shuffle, which has n! execution paths which match up one-to-one
Bijection

In mathematics, a bijection, or a bijective function is a function f from a set X to a set Y with the property that, for every y in Y, there is exactly one x in X such that f = y....
 with the possible permutations.

For an example of how this pigeonhole argument works on the nn shuffle, consider the simple case of shuffling only three cards, so that n=3. Then there are nn = 27 different possible execution paths (these are the 27 things to put in the pigeonholes). But there are only 3! = 6 ways to permute three cards (these are the 6 pigeonholes to put the things in). 27 is odd, and 6 is even, so 27 things cannot be divided evenly into 6 pigeonholes. Therefore, if we assume that the execution paths are equiprobable, then the outcomes cannot be, since at least two of the different outcomes must have different probabilities. Therefore the nn shuffle cannot be unbiased for n=3. Similar reasoning can be applied for other values of n > 2.

Another very easy mistake to make is to overlook the possibility of swapping an element with itself. The consequence of this error is that an element (for example, the top element) can never remain in its same position after the shuffle, when in reality, 1/52 of the time, it should. This was a critical flaw in the Enigma cipher
Enigma machine

The Enigma machine is any of a family of related electro-mechanical rotor machines that have been used to generate ciphers for the encryption and decryption of secret messages....
.

Whichever algorithm is chosen, it is important that a source of truly random numbers is used as the input to the shuffling algorithm. If a biased or (weak) pseudo-random source of random numbers is used, the output shuffles may be non-random in a way that is hard to detect, but easy to exploit by someone who knows the characteristics of the supposedly "random" number source.

Modulo bias
Another common source of bias in shuffling implementations is to use both a good shuffling algorithm and a true random number generator, but not to correctly reduce the output of the random number generator into the choice of which card to shuffle at a particular step. For example, if a 32-bit random number is used to choose one of 52 choices by using the modulo operator provided in most programming languages, it can be demonstrated using a pigeonhole argument
Pigeonhole principle

In mathematics, the pigeonhole principle, also known as Dirichlet's box principle, is exemplified by such things as the fact that in a family of three children there must be at least two of the same gender....
 that this choice cannot possibly be unbiased, since 232 cannot be evenly divided by 52. This is sometimes called "modulo bias".

This form of bias can be avoided in a number of ways. Probably the easiest involves deliberately limiting the number of usable outputs of the random number generator to a multiple of the number of choices to be made prior to performing the modulo operator, and re-trying the random number generator until a value within that range is produced. Although this algorithm is, strictly speaking, not guaranteed to terminate, given a true random number generator, the probability of this algorithm not terminating in a reasonable time is so small that it can be neglected for all practical purposes.

Pseudo-random shuffles
Even if only pseudo-random shuffles are required, there is another potential pitfall: the number of pseudo-random shuffles that can be generated cannot exceed the number of states that the pseudo-random number generator can take. For many older systems, this can be as small as 232, a number which is 58 orders of magnitude smaller than 52!, and thus 52-card shuffles generated using this system cannot possibly be unbiased. Indeed, since they can be completely enumerated, it is often possible to tell from the first few cards in such a pseudo-randomly shuffled pack what the remainder of the cards will be. Thus, in addition to all of the implementation problems above, to have any chance at all of generating a plausible pseudo-random shuffle, the pseudo-random generator must have in excess of log2 52! = 225.58 bits of internal state, preferably by a considerable margin.

It should also be noted that many pseudo-random number generators have non-random behavior in their low-order bits. If using the modulo operator as described above, with a small set of items to be shuffled, this non-random behavior in the low-order bits can produce very poor shuffles.

In online gaming

These issues are of considerable commercial importance in online gambling
Online gambling

Online gambling is a general term for gambling using the Internet. This article provides a brief introduction to some of the forms of online gambling, as well as discussing general issues....
, where the randomness of the shuffling of packs of simulated cards for online card games is crucial. For this reason, many online gambling sites provide descriptions of their shuffling algorithms and the sources of randomness used to drive these algorithms, with some gambling sites also providing auditors' reports of the performance of their systems.

See also

  • Card manipulation
    Card manipulation

    Card manipulation is the illusion of magic using a deck of playing cards. Card magic is commonplace in magic performances, especially in close up magic or parlor magic and street magic....
  • Mental poker
    Mental poker

    Mental poker is the common name for a set of cryptographic problems that concerns playing a fair game over distance without the need for a trusted third party....
  • Solitaire (cipher)
    Solitaire (cipher)

    The Solitaire cryptographic algorithm was designed by Bruce Schneier "to allow field agents to communicate securely without having to rely on electronics or having to carry incriminating tools", at the request of Neal Stephenson for use in his novel Cryptonomicon....


Footnotes

External links

Physical card shuffling:
Mathematics of shuffling:
  • Ivars Peterson's MathTrek:


Real World (Historical) Application: