Return to My Home.  
 
 

How All inPlay Shuffles the Deck

Anyone who has played cards, both in real life and on the All inPlay web site, has no doubt noticed there are times when the cards seem to come out darn funny. To make sure All inPlay games were fair, we launched an extensive investigation to verify the randomness of our shuffling algorithms. We also compared our results with what is typically found at casinos and other places where people play card games.

What we found was very interesting:
* It turns out that there are severe limitations to just how random you can shuffle cards by hand. Analysis shows that our shuffling algorithm is far MORE random than if you were to shuffle a deck of cards yourself by hand.
* Our shuffling algorithms have no idea what the rules of our games are, all they do is move the cards around in the deck randomly and then deal you the top card, whatever it may be.
* Apparently people (myself included) tend to assume that "random" means consistently boring and/or average. In fact, random simply means that - given a LARGE sample size, the results will average out. However, in any given small sample of the larger sample, all kinds of interesting patterns can arise.

The funny patterns you have witnessed are the infamous "good luck" or "bad luck" that people experience when dealing with a random number generator. What most of us call "Luck" tends to average out, but that doesn't mean that it has to average out over the course of a few hands, it might only average out over the course of hundreds or even thousands of hands.

If you are interested in how our game shuffles the cards, below we have placed a copy of the exact source code (AKA "the programming") and an explanation of how it works.

Blackjack and Crazy Eights

For blackjack and crazy eights we use a variant of the Knuth shuffle or Fisher-Yates shuffle algorithm known as Sattolo's algorithm.

This is widely acknowledged as the best computer shuffling algorithm.

The key to this algorithm is the source of random numbers. All inPlay uses the Mersenne Twister random number generator. While it's true that some random number generators have serious flaws, Mersenne Twister is one of the best computer generated methods. Bo Allen did an interesting comparison of a Windows implementation of generating random numbers and truly random numbers. All inPlay's head geek couldn't resist seeing how our Mersenne Twister faired and here's the results (sorry, it's graphical):

All inPlay Random Number Mapping

Draw Poker and Texas Hold'em

Here it our shuffling code for our poker games:

"
Line 1: for (int j = 0 ; j < 10 ; j++){
Line 2: for (int i = 0 ; i < topCardIndex ; i++){
Line 3: Card::swap(this->thisDeck[i], this->thisDeck[rand()%this->topCardIndex]); }}
"

That's it, 3 lines of code. Simple is beautiful <smile>.

Line 1 translates basically into "I'm a loop, do whatever is inside of me ten times"

Line 2 says "Hey, I'm a loop within a loop! Every time the big loop goes, I will run 52 times". The "topCardIndex" is the variable that tells the loop to run 52 times.

Line 3 says "Take the i'th card in the deck and swap it with a random card in the deck." You'll notice there is something called "rand()", this is the standard random number generator in C++, used by millions of programmers around the world for all kinds of things. It is not perfect, but it is pretty darn good, and it certainly doesn't know anything about poker, crazy eights, or any other game! In other words, it doesn't know what a full house is - it just generates a random "real" number between 0 and 1 (so it generates things like 0, 0.002345, 0.9875, 1, etc.).

The above code is the equivalent of you swapping two cards' positions in a deck, but doing that 520 times! In other words, each card, on average, is moved from its original position in the deck TEN TIMES.

It is our hope that the above code and explanation shows that:
1. All inPlay shuffles the deck better than most people are likely to
2. All inPlay's shuffler doesn't know a thing about poker, crazy eights, or any other game, so it has no idea how it could shuffle in such a way to make people get good hands or bad hands.
3. The shuffler is as random as you could expect a computer game to be, using the exact same random number generator used in the vast majority of computer games and science applications around the world.

Poker Odds

There are many sites on the web that list the odds of getting a certain hand in poker. Using the above shuffling algorithm (the same exact algorithm used in All inPlay's poker games) we ran half a million simulated hands. The cards were dealt to 5 "players" as they normally are (player 1 gets a card, player 2 gets a card, etc. After player 5 gets his first card, player 1 gets his second card. The deck was re-shuffled after each round. Here are the results, you'll find that they are in line with the odds in the "real world".

Hand
Number
Percent
Royal Flush
1
0.0002%
Straight Flush
6
0.0012%
Four of a kind
110
0.0220%
Full House
692
0.1384%
Flush
934
0.1868%
Straight
1944
0.3888%
Three of a kind
10727
2.1454%
Two Pairs
23669
4.7338%
One Pair
211677
42.3354%
Other
250240
50.0480%


Customer Support Home Page : My Home

 
 

 

Problems? Questions? Contact us.