Looks like I need to patch my shuffling routine...
http://www.uidaho.edu/imc/2002/p02-21.html
Shuffling Bias Discovered in Basic Strategy Trainer
(Taken from
http://www.blackjackinfo.com/news/bj022.htm)
This one's a real bummer for me. After a number of emails from visitors asking if the Blackjack Basic Strategy Trainer was dealing a random game of blackjack, I made a disappointing discovery. There was a flaw in the shuffling method that I used, which caused an unintentional bias in the game. The early hands being dealt in the shuffle were more likely to contain ten-valued cards than a truly randomly shuffled deck. Aces were actually less likely to appear, but the ten-card bias was enough to tilt the game in favor of the player.
The problem has now been corrected, but some of you may find an explanation of the problem interesting. (The rest of you can skip to the next story!)
Assume a single deck game, with 52 cards. My previous shuffle routine was as follows:
For each of the 52 spots in the deck, Swap that card with a randomly selected card (1 to 52).
That sounds reasonable, but it introduces a bias in the results. (Shuffling a 3-card deck (A,B,C) with this method leaves B as the first card 37% of the time, instead of the appropriate 33.3%.)
The new shuffling method is very similar, but no longer biased:
For each of the 52 spots in the deck, Swap that card with a card randomly selected between that spot and the end of the deck (n to 52).
Surprisingly, that subtle change of not allowing "backward swaps" makes the shuffle a random distribution.
It's frustrating to me that I've used an inaccurate shuffling routine over the years, and it's certainly an indication of how the smallest things matter when simulating a game like this. For those of you that have emailed me over the last few years asking about the integrity of the game on my site, I offer a sincere apology. The game was intended to be randomly dealt. Finally, it is.
Do the unbiased GE shuffle!
void shuffle_NR_RAND()
{
for (i = 1; i < (MAX + 1); i++)
{
temp = number[i];
j = i + rand(MAX + 1 - i);
number[i] = number[j];
number[j] = temp;
}
i = 0;
}