Humans are terrible at shuffling cards

This post is a bit geeky, so feel free to skip if you’re not into that.

A lot of games try to mimic activities that exist in the real world, even if the game itself is set in some fantasy universe. But even more down-to-earth games like poker or solitaire fit this definition. Even for these examples, the programmers must make some decisions on how realistic some of these simulated activities will be.

Card games, as the name implies, rely on a standard deck of playing cards as their base. From there you have all of the game actions like dealing, arranging and scoring. In order to make these games “fair”, they rely on a dealer or one of the players to shuffle and deal the cards. Dealing is pretty simple to implement, you just hand out cards one at a time to all of the players. A computer can do this almost instantly (from the standpoint of the human players) and although the rules may vary from game to game, it’s not all that hard to implement. But what about shuffling?

Simulating a deck of cards in software isn’t very difficult. One way is to construct an array of card objects that allow you to do things like change their order in the deck, be assigned to a player or whatever else your game needs. That first operation is basically what shuffling is all about. But now the programmer faces a choice.

What do I mean “faces a choice”? Think about how humans shuffle cards. The assumption is the order of the cards will be randomly changed once the shuffling is complete and not be dependent on the previous order. This is what makes a deck of cards fair. But humans aren’t able to accomplish that. If you take a fresh deck of cards, you’ll notice they’re in order by suit. Shuffle that deck, and you’ll see that along with some out of order cards there are vast blocks of cards still in the original ordering. If you play with that (physical) deck, you might notice certain card combinations reappear from game to game. Or you probably don’t notice anything at all since that’s just how it’s always worked.

Computers, on the other hand, are capable of being much more random. Electronic cards are also not easily dropped, don’t stick to each other and aren’t easily marked to signal their value. Without getting into a discussion of what random means, I will say that computers usually generate what are referred to as pseudorandom numbers. That is, they’re not pulled out of the air but are generated by a mathematical function. They seem random, but mathematicians and computer scientists know they’re not. Luckily, for the purposes of most games, that’s more than sufficient.

It’s still possible to make those pseudorandom numbers more random, though. Those mathematical functions take what is called a seed value. For a given seed, the numbers produced will always be the same. It’s helpful when you’re developing software but once you’re done that seed value is replaced by some other value. That value is expected to be taken from something connected to the external environment that doesn’t depend on anything in the software, although that varies from system to system. The result: card shuffling based on pseudorandom numbers generated from a somewhat random seed values results in new card orders that are sufficiently random and not dependent on previous ordering for our purposes.

Which, as I mentioned above, isn’t something a human can reliably do. So here’s the decision: Do you just go ahead and implement these random shuffles or attempt to emulate how a human would do it, knowing that it implies the resulting deck may contain some of the same card sequences it had before you shuffled? My limited experience says the former rather than the latter. And I totally understand why, it’s just that it makes some card games feel different than their real world counterparts*. They’re not wrong, they’re technically better than the real thing because they more fully achieve the goals of card shuffling, but they’re different.

Still, it’s important to keep in mind we’re not simulating something very important here, like a passenger airliner. No one is going to die as a result of a card game being more or less like the real world. Every game you play takes some liberties, sometimes because of difficulties in modeling or just to make the game play better. You probably don’t even notice them, provided the game itself is done well. Compared to something like a first person shooter card games are simpler and tend to be more repetitive so that these little differences are more apparent. Nevertheless, it would be interesting to compare the typical random shuffle with something more like human shuffling. I just might try that myself, although I don’t know precisely how yet.

If you have some insight, please share it in the comments.

*By different I really mean “harder to win”. You get some freebies in the real world because of the card ordering.

Leave a Reply