During the current covid-19 “stay-at-home” order, my family has been playing a lot of cards. Inevitably, someone will complain that the dealer hasn’t shuffled enough or is over-shuffling. And that leads to questions like “how can you even know if you have shuffled enough?”
Sounds like a job for simulations! Let’s start with some very simple models:
If we assume that, instead of the typical deck of Ace, 2, 3, …, Q, K in four different suits, the cards here are just numbered from 0 to 51, we simplify the simulation problem. Thus, the deck, when “new,” will be consecutively ordered from 0 to 51.
Furthermore, a simple measure of it’s likeness to the “new” state is the accumulated difference between consecutive cards:
Our “new” deck is defined as a simple list:
def ndeck():
return list(range(52))
And looks like:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51]
A shuffled deck is a new deck that is scrambled with the random.shuffle module of python:
def rdeck():
d = ndeck()
random.shuffle(d)
return d
… and will look something like:
[19, 45, 44, 40, 32, 33, 27, 37, 14, 10,
34, 5, 23, 8, 17, 21, 48, 6, 47, 24,
38, 15, 46, 29, 22, 12, 36, 42, 0, 41,
3, 2, 13, 11, 51, 30, 9, 28, 20, 49,
31, 16, 4, 50, 43, 39, 25, 1, 18, 7,
26, 35]
We will calculate scores of our decks with:
def deck_score(deck):
accum = 0
for i,card in enumerate(deck):
if i < len(deck)-1: # don't do final card
accum += abs(card - deck[i+1])
return accum
What scores do a new and a shuffled deck yield?
The new deck score is 51.
Shuffled decks (using the standard python module, “random”) gives us a range of scores. And the mean shuffled score is about 900.
Cutting the deck
Let’s start with a simple form of shuffling: just cutting the deck. This is the simple process of separating the deck into two piles of random thickness and then switching top and bottom halves. A function to do that for us:
def cut_deck(deck,minThin=4): # minThin controls how thin the piles can be
lower = minThin # the lower and upper limits to where the cut can be in the deck
upper = len(deck)-minThin
cut = random.randint(lower,upper) # location of the cut
new = deck[cut:] + deck[:cut] # bottom on top, top on the bottom
return new
And it looks something like
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 0, 1, 2, 3, 4, 5, 6, 7,
8, 9]
Pretty simple, eh?
A Null Hypothesis
A good place to start exploring is to guess what you are going to see as you start simulating. In this case, my first hypothesis is that as we cut the same deck consecutively, its deck score will climb toward that mean of a shuffled deck and that it will take about 12 cuts to make a random looking deck. Why 12? Just a guess.
I think it will look something like:
Consecutive cuts
If a new deck gives us a score of 51, and a deck cut once yields 101, what does cutting a deck twice yield?
151?
l = []
d = ndeck()
l.append(deck_score(d))
for i in range(10):
d = cut_deck(d)
#print(d)
l.append(deck_score(d))
print(l)
And the result of the consecutive cuts?
[51, 101, 101, 101, 101, 101,
101, 101, 101, 101, 101]
Huh?! Let’s look at a deck after a million cuts:
d = ndeck()
for i in range(1000000):
d = cut_deck(d)
The result:
[39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38]
Just a single cut!
Thinking a little more careful reveals what’s happening. The process of the second cut actually reconnects the two cards that were cut in the first cut!
This was a surprise to me. Consecutive cutting doesn’t actually change things that much, only the distance between the most recently cut cards. This is because the next cut actually “heals” the previous cut!
Thinking about it now, it makes sense. But that has not been my long held belief that cutting multiple times results in a shuffled deck. I admit that I had to pull out a real deck of cards to convince myself that this simulation result wasn’t an artifact. But it is not. Try it out.
Was this a surprise to you? Just about everyone in my house guessed that the deck would be pretty shuffled after a bunch of cuts. Probably a thinking error that magicians exploit.