TOPICS
Search

Riffle Shuffle


A riffle shuffle is a shuffle in which a deck is divided into two packets whose cards are interleaved while preserving their original order within each packet. A perfect riffle shuffle, also called a Faro shuffle, divides a deck of 2n cards into equal halves and interleaves their cards in strict alternation. An in-shuffle takes the first card from the bottom half. An out-shuffle takes it from the top half. Using an in-shuffle, a deck originally arranged from top to bottom as 1 2 3 4 5 6 7 8 would become 5 1 6 2 7 3 8 4. Using an out-shuffle, the deck order would become 1 5 2 6 3 7 4 8. Riffle shuffles are used in card tricks (Marlo 1958ab, Adler 1973), and also in the theory of parallel processing (Stone 1971, Chen et al. 1981).

For a positive even number n of cards, an out-shuffle is implemented in the Wolfram Language using Riffle, for example:

  Riffle @@ Partition[Range[n], n/2, n/2, 1, {}]

For an in-shuffle of 2n cards, number the positions from 1 through 2n. The card at position k moves to position 2k modulo 2n+1. For an out-shuffle, number the positions from 0 through 2n-1. The first and last cards remain fixed, and each interior card moves from position k to position 2k modulo 2n-1.

Therefore, in-shuffling an even number n cards n times when n+1 is prime results in the original card order. Similarly, out-shuffling an even number n cards n-2 times when n-1 is prime results in the original order (Diaconis et al. 1983, Conway and Guy 1996). An ordinary deck of 52 cards is returned to its original order after 52 in-shuffles, but after only eight out-shuffles!

In the Gilbert-Shannon-Reeds model, for a deck of n cards, the first packet size has a binomial distribution with parameters n and 1/2. Given the cut, each interleaving that preserves the order within the packets has equal probability. For independent shuffles in this model, Aldous (1983, p. 266) showed that the mixing time at any fixed total variation distance threshold strictly between 0 and 1 is asymptotic to (3/2)log_2n as n->infty. Aldous and Diaconis (1986, p. 345) suggested seven riffle shuffles to get close to random for a deck of 52 cards. For this deck size, Bayer and Diaconis (1992, p. 296) give total variation distance from the uniform distribution of approximately 0.334 after seven shuffles, 0.167 after eight, and 0.085 after nine.

Morris (1994) discusses aspects of the perfect riffle shuffle (in which the deck is cut exactly in half and cards are perfectly interlaced). Ramnath and Scully (1996) give an algorithm for the shortest sequence of in- and out-shuffles to move a card from arbitrary position i to position j. This algorithm works for any deck with an even number of cards and is O(log_2n).


See also

Cards, Shuffle

Explore with Wolfram|Alpha

References

Adler, I. "Make Up Your Own Card Tricks." J. Recr. Math. 6, 87-91, 1973.Aldous, D. "Random Walks on Finite Groups and Rapidly Mixing Markov Chains." In Séminaire de probabilités XVII 1981/82 (Ed. J. Azéma and M. Yor). Berlin, Germany: Springer-Verlag, pp. 243-297, 1983. https://doi.org/10.1007/BFb0068322.Aldous, D. and Diaconis, P. "Shuffling Cards and Stopping Times." Amer. Math. Monthly 93, 333-348, 1986.Ball, W. W. R. and Coxeter, H. S. M. Mathematical Recreations and Essays, 13th ed. New York: Dover, pp. 323-325, 1987.Bayer, D. and Diaconis, P. "Trailing the Dovetail Shuffle to Its Lair." Ann. Appl. Probability 2, 294-313, 1992.Chen, P. Y.; Lawrie, D. H.; Yew, P.-C.; and Padua, D. A. "Interconnection Networks Using Shuffles." Computer 14, 55-64, Dec. 1981. https://doi.org/10.1109/C-M.1981.220297.Conway, J. H. and Guy, R. K. "Fractions Cycle into Decimals." In The Book of Numbers. New York: Springer-Verlag, pp. 163-165, 1996.Diaconis, P.; Graham, R. L.; and Kantor, W. M. "The Mathematics of Perfect Shuffles." Adv. Appl. Math. 4, 175-196, 1983.Gardner, M. Mathematical Carnival: A New Round-Up of Tantalizers and Puzzles from Scientific American. Washington, DC: Math. Assoc. Amer., 1989.Golomb, S. W. "Permutations by Cutting and Shuffling." SIAM Rev. 3, 293-297, 1961.Herstein, I. N. and Kaplansky, I. Matters Mathematical. New York: Harper & Row, 1974.Mann, B. "How Many Times Should You Shuffle a Deck of Cards." UMAP J. 15, 303-332, 1994.Marlo, E. Faro Notes. Chicago, IL: Ireland Magic Co., 1958a.Marlo, E. The Faro Shuffle. Chicago, IL: Ireland Magic Co., 1958b.Medvedoff, S. and Morrison, K. "Groups of Perfect Shuffles." Math. Mag. 60, 3-14, 1987.Morris, S. B. "Practitioner's Commentary: Card Shuffling." UMAP J. 15, 333-338, 1994.Morris, S. B. and Hartwig, R. E. "The Generalized Faro Shuffle." Disc. Math. 15, 333-346, 1976.Numberphile. "The Best (and Worst) Ways to Shuffle Cards." Mar. 23, 2015. https://www.youtube.com/watch?v=AxJubaijQbI.Peterson, I. Islands of Truth: A Mathematical Mystery Cruise. New York: W. H. Freeman, pp. 240-244, 1990.Ramnath, S. and Scully, D. "Moving Card i to Position j with Perfect Shuffles." Math. Mag. 69, 361-365, 1996.Sloane, N. J. A. Sequences A059952 and A059953 in "The On-Line Encyclopedia of Integer Sequences."Stone, H. S. "Parallel Processing with the Perfect Shuffle." IEEE Trans. Comput. C-20, 153-161, 1971. https://doi.org/10.1109/T-C.1971.223205.Veritasium. "The Strange Math That Predicts (Almost) Anything." Jul. 25, 2025. https://www.youtube.com/watch?v=KZeIEiBrT_w.

Referenced on Wolfram|Alpha

Riffle Shuffle

Cite this as:

Weisstein, Eric W. "Riffle Shuffle." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/RiffleShuffle.html

Subject classifications