The Thorp shuffle is a model of a riffle shuffle, introduced by Edward O. Thorp in 1973 in his study of nonrandom shuffling and the game of faro. The deck is split into two equal packets. For each pair of current bottom cards, a fair coin decides whether the left card or the right card is dropped first, and then the other card is dropped. This continues until both packets are empty.
As the number of rounds approaches infinity, the output of the Thorp shuffle approaches the distribution of a uniformly sampled permutation. For a deck whose size is a power of two, the shuffle is equivalent to a maximally unbalanced Feistel network. It has applications in cryptography, including private information retrieval.
For an even number of cards, split the deck into two equal packets. Keep the order inside each packet, and pair the cards having the same depth in the two packets. For every pair toss an independent fair coin, and use that coin to decide which member of the pair occupies the earlier of the two corresponding output positions. Thus there are independent coin tosses in one shuffle.
Number the positions from to . For every pair of cards in positions and , a coin decides which one will be placed in position and which one in position , where . Repeat with fresh random choices for each round.
For a deck of cards, write each position as a -digit binary number , with first bit and remaining bits . The shuffle pairs positions whose binary numbers differ only in that first bit, namely and .
For each pair, toss a fair coin independently to decide whether to swap the two cards. Let for a swap and otherwise. Moving the first bit of the resulting position number to the end completes the shuffle: where denotes exclusive OR, or addition modulo two.
In an eight-card deck, the card at is paired with the card at . Without a swap, the rotation sends it to ; with a swap, it moves first to and then to .
A block of Thorp shuffles on cards is equivalent to one butterfly switching network. One way to visualize what the network does is as follows. Take a -dimensional hypercube and color its edges by coordinate direction. Put numbered balls on the vertices of the cube. Go sequentially through the colors, and for each edge of the current color, switch the balls at its ends with probability one half, independently of the other edges.
A ball placed at any starting vertex has the same probability of finishing at any vertex. This uniform distribution for one ball does not imply that the whole permutation is uniform.
The total number of shuffles required to make all shuffling outcomes have almost uniform distribution (equally likely, independent of initial card order) is called the mixing time. The acceptable error is expressed as total variation distance.
For cards, Ben Morris obtained a full-deck upper bound of in big O notation. Morris subsequently proved an bound for arbitrary even , and then, for , reduced the full-deck bound to . Morris, Rogaway and Stegers also obtained estimates for subsets of the cards, which can mix much faster than the whole deck.
An -card deck has possible orders, but one round of the Thorp shuffle has only possible outcomes. After rounds, at most orders can be reached. To come within a fixed total variation distance of uniform, at least orders must be reachable. This forces to grow at least linearly with , giving an information-theoretic lower bound.
The resulting position of a single card can be computed without performing the whole shuffle, by checking only a small number of bits. The same holds for the inverse shuffle. In a cryptographic implementation, a seed for a pseudorandom generator, together with a description of how many rounds to run, specifies the permutation. The seed is used to generate the bits in each step and allows the shuffle to be evaluated in either direction.
In ThorPIR, a protocol for private information retrieval from a single server, the client and server first run a joint preprocessing algorithm. The client can then retrieve elements from the database privately, without revealing which element was requested. During preprocessing, the server computes the Thorp shuffle under fully homomorphic encryption.
This article incorporates text by Efraim Gelman and Amnon Ta-Shma available under the CC BY 3.0 license.
This article incorporates text by Ben Fisch, Arthur Lazzaretti, Zeyu Liu and Charalampos Papamanthou available under the CC BY 4.0 license.
This article incorporates text by Yunjiang Jiang available under the CC BY 4.0 license.
Passages from these sources have been reproduced and adapted, with omissions and changes to notation and wording.