Tuesday, March 24, 2015

Shuffling

Robbie Strazynski (@cardplayerlife) pointed me to this YouTube video about the mathematics of shuffling a deck of cards into true randomness:




You might watch that and think, "OMG! The way poker dealers shuffle doesn't come anywhere close to meeting that standard!" And you'd be right. But you wouldn't be right to worry about that fact.

When the professor is talking about a deck that is not fully randomized, so that one could guess the next card more often than chance alone would dictate, he's talking about having started from a deck that is as it comes from the factory--or, to use the casino term, a deck that has been "spaded"--with the cards in rank order within each suit.

But if you don't know what order the cards are in before the shuffling begins, it makes no difference how much shuffling you do. Your ability to guess the position of any specified card is 1 out of 52 before the shuffling procedure begins (by definition of what it means not to know what order the cards are in), and it is the same after one riffle shuffle, or two, or ten.

For purposes of a poker game, it makes no difference whether the order of the cards in the deck after the shuffling process can pass a statistical test for random distribution compared to the order they were in before the shuffling process. All that matters is whether any player can know or guess the identity of any card. For example, suppose that I see that the first card I'm dealt is the queen of clubs. Can I guess the identity of the next card--which will be dealt to the player on my left--with any accuracy better than a 1 in 51 guess based on that one piece of information? No. And that's all that matters.

Of course, if one is paying attention, one can know at least roughly the position of some of the cards before the shuffle, because you can watch the dealer turn face-down the board cards and any players' hands that were exposed, and watch where those cards end up in the deck. Suppose you notice that the river card on the previous hand was the ace of diamonds, and the way the dealer gathers up the cards causes that ace to now be on the bottom of the deck before the shuffle.

You could, if you really wanted to, watch what the dealer does, and get a general sense of where that ace ends up. The dealer will typically do two riffle shuffles, which will leave the ace within the bottom few cards. Next he will do a "boxing" shuffle, which is an on-the-table equivalent to the second type of shuffling shown in the video. It moves a few cards at a time as a packet from the top of the deck to the bottom. So now you know that the ace is somewhere near the top of the deck--probably within the top ten cards. Now the dealer does another riffle, which will leave the ace near the top. Finally, the deck is cut, which will put that ace somewhere in the middle.

If you're playing ten-handed hold'em, 20 cards will be dealt to the players. Is that enough that one of the last ones dealt will be that ace of diamonds? Maybe, maybe not--it depends on how large the packets of cards were during the boxing shuffle, and on where the cut was made. If the ace doesn't get to one of the players, will it end up on the board? Maybe, maybe not. The dealer will go through 8 more cards (5 on the board and 3 burn cards), so the river will be what had been the 28th card in the deck at the start of the hand. But the ace might be above or below that point. You can't be sure.

This shuffled deck would not pass every test for randomness, because you could, for example, profitably bet that the ace of diamonds will be found in the middle one-third of the deck, which will prove to be true more than it being in the top or bottom thirds--a condition that would not obtain for a truly randomized deck of cards. But in real-world practice, your ability to track the position of a card is so diluted, and the poker edge you could gain by a general sense of where in the deck that one card will be found is so weak that they might as well be zero.

And all of that is for just one card, and only for a person who is really watching closely. If the dealer does a wash of the cards before the shuffling (some casinos' procedures require that, some leave it up to the dealer, or it may be done at a player's request), it's pretty unlikely that you'll be able to follow the position of even that one card you were trying to track.

Furthermore, if the casino uses a Shufflemaster machine with alternating decks, you have no chance at all, because the machine truly randomizes the deck. It has a random number generator, and moves each card to a randomly selected spot (1 through 52) in the newly ordered deck.

All of which is a very long way of saying this: The standard poker room shuffling procedure, if done correctly, is plenty good enough. It may not pass rigorous statistical tests of randomness, but it effectively leaves every player thoroughly ignorant of where any card is going to show up, which is all that matters.

8 comments:

THETA Poker said...

Wow, that's a great video. I knew the overhand shuffle was bad (see http://www.thetapoker.com/shuffling/#footnote1), but I didn't realize how bad it was. I added a link to your post at the bottom of mine.

Thank you Poker Grump and Robbie Strazynski.

Memphis MOJO said...

I've always wondered if it made any difference at poker as to how many times the deck was riffled, and I guess it doesn't really matter.

I think bridge is slightly different regarding how many times the deck should be riffled. I don't want to get too much into bridge, but it's a partnership game and let's say your side bids to a contract that will make if your opponents' heart suit splits 3-2, i.e. one opp has three hearts and the other has two (either one having the three/two). According to odds, this will happen ~68% (I forget the exact number) of the time.

Some bridge deals are hand-shuffled, and some are dealt by a computer and then given to the players. They've found that if the deck is hand shuffled/riffled only (let's say) three or four times (instead of seven), the percentage is much higher than 68%. If the deck was shuffled by the computer, it will (over time) happen exactly 68% of the time like it's supposed to. So, in bridge it still matters how many times the deck is riffled.

Thanks for the link -- interesting stuff to me.

chezztone said...

No, Grump, the collective ignorance of what's coming is not "all that matters." We really do want the cards to be randomized. When you have KQ and I have 88 and we're all in preflop, we want the odds to be what we think they are (about 50-50) of either of us winning. Imagine a game where the dealer doesn't shuffle at all, but the players have bad memories, so they don't remember what's coming up. It's not a fair game. Even if they don't know what to expect, the cards aren't falling randomly, so the odds the players depend upon to make their decision do not hold, and the game is rigged. When dealers shuffle fewer than seven times (or wash for less than 30 seconds), the game also is rigged, to some extent.

Rakewell said...

Chezztone, I think you don't understand what those probability numbers mean. If we're all in with KQ vs. 88, in the most absolute sense there is no probability to the outcome. It is fixed and determined by the order of the cards in the dealer's hand. One of us is 100% to win, the other 0%. We just don't know which is which. Saying that the probability of 88 winning is 55% (or whatever the actual number is) is not really the probability for winning this hand, but a long-term, cumulative estimate. That is, if we get into this same situation 100 times, 88 will win about 55 of them, and KQ about 45 of them. And THAT remains true even if the shuffling doesn't meet statistical standards of randomization. That is true because inadequate shuffling does not introduce any systemic bias that will favor either 88 or KQ over the long run. And, as I said, the long run is the only thing that the 55% number is about.

chezztone said...

Maybe focusing on one hand doesn't make the point clear, sorry. But we want the deck to be random, even in the short run, for it to be a fair game. If you imagine the situation where the deck is the same every time, but the players don't remember that, you might understand the difference between a random deck and a nonrandom one. If it's not random, the game isn't what we think it is, and therefore isn't fair. If it's true for bridge it is for poker or any other game. Thank you.

Rakewell said...

You're posing a false dichotomy, between a "random" deck and a "nonrandom" one. That misunderstands the situation. There are degrees or shades of randomization.

It's true that a deck arranged exactly the same way every time, with no player memory, would be unfair. But since nothing even remotely like that is either possible or under consideration here, it's a purely academic point.

The deck does not need to be able to pass all statistical tests of randomness for you to get the 55/45 (or whatever) distribution of outcomes over a large number of trials. The only requirement is that the shuffling procedure, however statistically flawed it may be, not introduce a SYSTEMIC bias that will over the long run favor a particular outcome in any given matchup, such as 88 vs KQ. The standard casino shuffling procedure passes that test, in addition to meeting the requirement that no player be able to gain an advantage by being able to predict the position of any card.

Anonymous said...

Chezztone, I think you're also overestimating the ability of people - even computers - to truly randomize. Are dice truly random? No, given a known starting position and a calculation of momentum and angular velocity, their outcome can be predicted. Is a computer random number generator truly random? Not always - sure, there are some sophisticated tools that take advantage of truly random quantum-level events, but most random number generators have you wave your mouse around. To varying degrees, these pseudorandom number generators can be exploited, and people who write code for online gaming are (or should be) well aware of the flaws of their random number generators. Even the first generation shuffling machines in Vegas were flawed when they were first introduced - some mathematicians made a lot of money at the blackjack tables before the fixed the flaws.

To that extent, shuffling in live poker is like a vault in live banking. We can be okay with random enough, just as we're okay with secure enough. Given infinite information and infinite time, someone can probably crack the system, but to a regular person given the regular time between hands, the pseudorandom system is as good as a truly random system.

Someday when cyborgs are allowed to play poker, someone with an ocular implant is going to be able to figure out peoples' cards based on infinite memory and careful observation of the shuffle. Until then, we can cut corners - is the procedure we have in place good enough to cover 99.9% of the people and 99.9% of the situations we're going to face? Yes? Shuffle up and deal.

chezztone said...

Well, Grump, we don't have to overestimate, we don't have to estimate at all, what it takes to truly randomize a deck of cards. The prof did it and told us about it in that video you posted: seven riffles. That's it!