View Single Post
  #2  
Old 05-02-2005, 02:36 AM
Siegmund Siegmund is offline
Senior Member
 
Join Date: Feb 2005
Posts: 415
Default 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]
Reply With Quote