PDA

View Full Version : If I wanted to shuffle 8 decks of cards


EnderFFX
10-26-2005, 12:03 AM
And I decided to this shuffle by picking two random cards from the 8 decks ans swapping their position, how many iterations would I need to have a properly shuffled 8 decks of cards?

Is this a good method of shuffling for statistial analysis?

alThor
10-26-2005, 11:51 AM
[ QUOTE ]
And I decided to this shuffle by picking two random cards from the 8 decks ans swapping their position, how many iterations would I need to have a properly shuffled 8 decks of cards?

Is this a good method of shuffling for statistial analysis?

[/ QUOTE ]

Do it this way. Randomly swap the card in slot 1 with the card in a randomly chosen slot (possibly itself!). Then swap slot 2's card with a card randomly chosen from slot 2...n. Swap 3's into 3...n, etc. This takes n-1 iterations, and is guaranteed random (up to the limits of your rng).

alThor

10-26-2005, 02:05 PM
In all the programs I've written a shuffle function I've just taken each card, 0..51 and swapped it with a random card. I haven't noticed any problems with this method starting with an in order deck playing Blackjack.

TomCollins
10-26-2005, 03:12 PM
This algorithm is flawed and will result in a biased deck.

Think about a 3 card deck. There are 27 possibilites that are equally likely. There are only 6 distinct decks. How can you divide the 27 possibilities into 6 decks? Obviously one distribution happens more than another.

TomCollins
10-26-2005, 03:52 PM
To clarify, the following distribution happens:

ABC -4
ACB -5
BAC -5
BCA -5
CAB -4
CBA -4

So we only see C as the first card 8/27 times, and we see B 10/27 times. Definitely not fair.

10-26-2005, 04:20 PM
Aye, I had just run a simulation after realizing you were right through ten million hands:

ABC - 1,482,563
ACB - 1,850,627
BAC - 1,851,344
BCA - 1,851,525
CBA - 1,481,467
CAB - 1,482,474

pzhon
10-26-2005, 04:33 PM
[ QUOTE ]
And I decided to this shuffle by picking two random cards from the 8 decks ans swapping their position, how many iterations would I need to have a properly shuffled 8 decks of cards?

[/ QUOTE ]
My guess is that this behaves a lot like the top-in shuffle, which in some sense takes about n log n iterations to randomize a deck with n cards.

However, the best I could find was that about 2 n^2 iterations suffice to randomize the deck. See problems 6 and 7 on this homework assignment (http://www.stat.uchicago.edu/~lalley/Courses/313/HW2.pdf).

More precisely, there is a random (but dependent) stopping time at which the deck is uniformly shuffled so that the expected stopping time is 2n^2. The probability that the stopping time is greater than 2n^2+k decays exponentially in k.

[ QUOTE ]

Is this a good method of shuffling for statistial analysis?

[/ QUOTE ]
No. There are fast, effective algorithms. This is not one of them.

pzhon
10-26-2005, 04:50 PM
[ QUOTE ]

My guess is that this behaves a lot like the top-in shuffle, which in some sense takes about n log n iterations to randomize a deck with n cards.

However, the best I could find was that about 2 n^2 iterations suffice to randomize the deck.

[/ QUOTE ]
There is a claim that about n log n random transpositions suffice here (http://www.aimath.org/WWN/mixingtimes/mixingtimes.pdf). See the comments by Speaker III.

AaronBrown
10-26-2005, 07:03 PM
One simple principle that is too-often overlooked is that it helps to start with a mixed up deck. Minor imperfections in your shuffling algorithm make a lot less difference if you start with a randomized deck than if you start with Ace of Spades 1, Ace of Hearts 2 and so on.

The theoretical calculations are typically based on whether a perfectly-informed mathematician could find any +EV bet on any card combination. In most games, it doesn't make much difference to know that the probability of 5 of clubs being in position 8 from the top of the deck is slightly more or less than 1 in 52. Moreover, it takes an astronomical number of hands for someone to be able to notice this. But it can make a lot of difference to know, and you can notice pretty fast, if, say, two Aces in a row occur with probability slightly different than 1/17.