Two Plus Two Older Archives

Two Plus Two Older Archives (http://archives2.twoplustwo.com/index.php)
-   Probability (http://archives2.twoplustwo.com/forumdisplay.php?f=23)
-   -   Shuffle Algorithm (http://archives2.twoplustwo.com/showthread.php?t=243836)

Japster 05-02-2005 12:39 AM

Shuffle Algorithm
 
I guess this question is more for Sklansky or Malmuth but here it is. What is the best way to create an unbiased shuffle in software. I know of some ways that would work but I was curious as to what you guys used and how accurrate it actually is. I am working on some software for learning different gambling games. Just curious.

Jack

Siegmund 05-02-2005 02:36 AM

Re: Shuffle Algorithm
 
All you need is to select a uniform random number between 1 and 52! ~ 8.07x10^67 ~ 2^226. The result as as good as your random number generator is.

There are various sources for real random numbers such as HotBits or you can use the pseudo-RNG algorithm and very-large-integer package of your choice. Mersenne Twister seems to be the algorithm of choice these days.

If you don't require cryptographically strong randomness, e.g. for quick and dirty simulation code, it will probably make very little difference what you use. I freely admit that in my own programs, I use the good old-fashioned

FOR A = 1 TO 51
B = INT(RND*(53-A))+A
SWAP CARD(A),CARD(B)
NEXT

method with the system's built-in RNG. Nothing too bad happens. [img]/images/graemlins/crazy.gif[/img]

LetYouDown 05-02-2005 01:11 PM

Re: Shuffle Algorithm
 
The "swap card" method is the method I've used in some software I created where I wanted to just test the odds of getting certain hands. More of a hobby project than anything. Do you find that you can predict the order of the cards somehow, if this method is used? Say you were to swap 100k times.


All times are GMT -4. The time now is 12:08 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.