 Shuffling a Card Deck | Combine

### Shuffling a Card Deck

At Combine, we play board games during so-called "Game Nights". On several occasions, there have been discussions regarding how to shuffle cards efficiently. But what does it mean to shuffle cards efficiently?

## Introduction

At Combine, we play board games during so-called “Game Nights”. On several occasions, there have been discussions regarding how to shuffle cards efficiently (i.e. having an unpredictable order of the cards).

A deck of ordinary playing cards consists of four suites of 13 cards each giving a total of 52 cards. The total number of permutations of the card deck is given by:

$$P^n_r = \frac{n!}{(n-r)!}$$

where $$n = 52$$ is the total number of cards and $$r = 52$$ is the length of the sequence we want to generate from the $$n$$ cards. Since $$n = r$$ we obtain $$n! = 52!$$, which is approximately $$8 \cdot 10^{67}$$ combinations.

How to shuffle cards have been studied before and also discussed in other ways, and these sources have been used as a foundation for this text.

Given a deck of 52 cards, each card is numbered from 0 to 51 in order ($$F_i = i$$). After shuffling the deck we then know the id of each card in the new order. The Shannon Entropy is then calculated by first estimating the distribution of distances between each card in order:

$$\Delta F_j = F_{j+1} – F_j$$

The Shannon Entropy is then calculated using

$$E = \sum_{j=0}^{51} -p_j \log_2(p_j)$$

The variable $$p_j$$ is a normalized histogram of distances between cards.

The maximum possible entropy is $$\log_2(52) = 5.7$$ (measured in the unit “bits”), which is useful as a reference.
According to literature, it is enough to cut the deck and riffle shuffle seven times to obtain an unpredictable order.

## Overhand Shuffle

Not everyone is able to perform the riffle shuffle and might instead use the overhand shuffle. We experimented with the overhand shuffle, wrote down the order of the cards for each shuffle, and ended up with the following increase in entropy (the red line is the maximum possible entropy). The first iteration does not increase the entropy at all since the deck was only cut once without any shuffling taking place.

## Hash Shuffle

One idea which was discussed at one Game Night was to shuffle cards using a method similar to how hash values are calculated in computer science. This is a deterministic shuffling method, but by adding some random elements, like cutting the deck, we get some interesting results.

The idea is to choose a number of piles and divide the cards between them. This would force cards to interleave with each other, introducing a distance between them. Just doing this once without any random elements gives the following entropies for different numbers of piles: If we apply the hash shuffle twice and try all combinations between 2 and 10 piles we find that using 5 piles to start with and then 5 piles a second time again gives the highest entropy. In practice, you should cut the deck between each operation as well. If you want to repeat the hash shuffle for a fixed number of piles you should obviously avoid 2 and 4 piles. ## Riffle Shuffle

The riffle shuffle is claimed to be one of the best ways to shuffle a deck of cards. And, indeed, given the Shannon Entropy measure the riffle shuffle is by far the best way to shuffle according to the following figure: The entropy rises very fast. Using other measures it is claimed that 7 riffle shuffles should be enough, and more than $$2 \log_2(52) = 11.4$$ shuffles is not necessary.

## Conclusion

When shuffling you should use the riffle shuffle. Just make sure that you cut the deck between each shuffle since the top and bottom cards tend to get stuck otherwise.