
The Math of Card Shuffling - danso
http://fredhohman.com/card-shuffling/
======
evanb
There's a great numberphile with Persi Diaconis all about shuffling:
[https://www.youtube.com/watch?v=AxJubaijQbI](https://www.youtube.com/watch?v=AxJubaijQbI)
The extra footage is fantastic, too.

~~~
fredhohman
Author here: I link to this video in the post—it was what originally sparked
my interest to do the visualization! The whole channel is really great.

~~~
edanm
Great article!

Where can I find other things you've written? I tried searching your website,
but it looks like the blog is pretty inactive.

On another note - I saw that you used Idyll for this site. I haven't heard of
it but am very interested - what do you think about it?

~~~
fredhohman
Thanks!

This was a side project for me. I'm doing my PhD right now so all my current
writing is funneled into my research. But Idyll is great for these types of
articles, so I'm looking forward to doing more in the future. The creator of
Idyll is also a good friend of mine so I may be a bit biased :)

Here's the homepage: [https://idyll-lang.org/](https://idyll-lang.org/)

Check out other examples too: [https://idyll-lang.org/gallery](https://idyll-
lang.org/gallery)

------
have_faith
There is a very interesting false card shuffle called the Faro Shuffle. A
trick most card magicians/technicians can spend a lifetime perfecting. If you
split the deck perfectly, riffle shuffle perfectly such that each card lands 1
for 1 with each other, and repeat 8 times, the deck will be fully restored to
it's original order.

No one uses it in live tricks due to the dexterity required and the fact that
to a layman the effect is identical to other easier false shuffles.

------
lorenzhs
There’s a nice but somewhat technical analysis of card shuffling things in
“Proofs from THE BOOK”, a book I can highly recommend to the mathematically
interested (requires some mathematical background, like what you’d get in a
good CA curriculum, but nothing fancy). This link to an older edition _should_
hopefully work:
[http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.167...](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.167.5285&rep=rep1&type=pdf)

------
trombonechamp
There is a difference between "random in theory" and "random in practice"...
see: [http://blog.maxshinnpotential.com/2017/11/05/how-you-
should-...](http://blog.maxshinnpotential.com/2017/11/05/how-you-should-be-
shuffling-cards.html)

~~~
SomewhatLikely
For instance, the assumption that a single card riffle into a deck will put it
in a random location. In reality it would probably be something more like a
bell curve around the middle.

~~~
fredhohman
Author here. Definitely true that you need a random number generator for this
to work. See this relevant response to my tweet with a paper describing how
bad humans are at picking random numbers:
[https://twitter.com/fredhohman/status/1007718733186396161](https://twitter.com/fredhohman/status/1007718733186396161)

~~~
trombonechamp
There is actually a pretty simple algorithm people can use (in real time) if
they want to generate random numbers:
[http://blog.maxshinnpotential.com/2017/07/05/can-humans-
gene...](http://blog.maxshinnpotential.com/2017/07/05/can-humans-generate-
random-numbers.html)

------
jedberg
That's not how you shuffle cards though. First you cut the deck, such that the
bottom card is somewhere near the middle. Then you split and riffle.

If you do that seven times you get a random deck.

If you do it three times you get a fairly random deck, but you'll get clumps
of cards together. That's why casinos usually use three cut/riffle steps, and
why you can have an advantage playing with a hand shuffled deck.

It's also why I will never play with a machine shuffled deck. Because _those_
are actually shuffled seven times, and are truly random.

~~~
Kartificial
So why won't you play a truly random shuffled deck?

~~~
jedberg
Because then I have no advantage over the casino. With a hand shuffled deck,
you get clumps of high cards together from the last set of hands, which gives
an advantage to the player. If you can ride out waiting for the clumps, you
can beat the house.

------
everdev
> most of the time, a deck of cards is shuffled using a riffle. Here’s a
> question: how many times do you have to riffle a deck of cards before it is
> completely shuffled? It’s a tricky one, but math has us covered: you need
> seven riffles.

------
partycoder
The behavior of the last cards is interesting.

This can be improved by splitting the deck between riffles.

------
pjungwir
A high school friend told me the same thing around 1993-1995: you have to
shuffle it seven times. He said he read it in Wired magazine. I've tried to
find the article a few times since, but never been successful.

------
kpskps
I'd like to understand how you came up with the equation summing up to 235

~~~
edanm
If you take the 52 out of the sum, it becomes:

52 * (1/1 + 1/2 + 1/3... +1/n), where n=52. This is the harmonic series. I
didn't know off-hand of a formula for the sum of the harmonic series, so I
searched, and apparently, there _is_ no closed form formula for this. So you
either have to actually calculate this number, or find an approximation.

Personally, I just plugged it into Wolfram alpha:
[http://www.wolframalpha.com/input/?i=1%2F1+%2B+1%2F2+%2B+......](http://www.wolframalpha.com/input/?i=1%2F1+%2B+1%2F2+%2B+...+%2B+1%2F52).

The result is, approximately, 4.538. And indeed, 4.538 * 52 = 235.976, which
rounds down to 235 (not sure why the author rounded down).

Thanks for asking this!

------
wjnc
Since I lack the skills to riffle succesfully, I usually sort and shuffle
based on the properties of the game at hand. I usually sort somewhat randomly
to stacks, where the number of stacks is larger than the regular set in the
game (but < 2 times the regular set). After that, a few quasi riffles and I
feel I've made the next game sufficiently random from the sorting that the
last game gave. Wonder if I could wrap my math around formalising that.

------
8bitsrule
Riffle shuffle leaves many cards that were near the bottom still near the
bottom. That's not exactly what I'd call 'truly random' ... which would be ANY
card has an equal chance of being ANYWHERE in the deck.

A better alternative would be to put the bottom-third of the deck on top, then
riffle.

------
jedimastert
I don't think I saw is in the article, but what is the definition of a
properly shuffled deck?

~~~
GuB-42
Just on top of my head: a deck where the original order and shuffled order are
completely uncorrelated. Or a deck where the shuffle process yields every
possible order with equal probability. These two are equivalent if all cards
are the same for the purpose of shuffling (no bias).

~~~
praptak
Can 7 riffles fully reverse the order of cards?

~~~
edanm
Sure. Why couldn't it?

------
vermontdevil
80,658,175,170,943,878,571,660,636, 856,403,766,975,289,505,440,
883,277,824,000,000,000,000

Quite a big number!

~~~
andrepd
How big, you ask? This big:
[https://czep.net/weblog/52cards.html](https://czep.net/weblog/52cards.html)

~~~
sjcsjc
This link always gets posted here when this subject comes up. If you haven't
read it it's well worth a look. It's a very effective way of conceptualising
the vastness of big numbers.

------
sdenton4
This article didn't have enough Fourier transforms on the symmetric group.

~~~
cosmic_ape
and not enough coupling arguments.

