On May 13, 10:26 pm, bob <
b...@coolfone.comze.com> wrote:
> On Wednesday, May 8, 2013 4:35:18 PM UTC-5, Mok-Kong Shen wrote:
> > I want to compare in a practical sense two methods of random
>
> Why would you not use the method of random permutation that is theoretically perfect? Isn't it pretty much trivial to implement and not very hard to understand?
Good question. I'm going to guess he's worried about speed,
but still don't know how expects to improve on Fisher shuffle,
which only needs 51 small random integers for a 52-card deck.
Perhaps he doesn't know that you can get several independent
small integers from a single random-number, e.g. to get a
12-permutation from a 31-bit random:
int a, b;
do a = rand();
while (a >= 1916006400);
b = a % 12; a /= 12; doshufstep(12, b);
b = a % 11; a /= 11; doshufstep(11, b);
b = a % 10; a /= 10; doshufstep(10, b);
b = a % 9; a /= 9; doshufstep( 9, b);
b = a % 8; a /= 8; doshufstep( 8, b);
b = a % 7; a /= 7; doshufstep( 7, b);
b = a % 6; a /= 6; doshufstep( 6, b);
b = a % 5; a /= 5; doshufstep( 5, b);
b = a % 4; a /= 4; doshufstep( 4, b);
b = a % 3; a /= 3; doshufstep( 3, b);
b = a % 2; a /= 2; doshufstep( 2, b);
(A good compiler will remember the quotient
after doing the modulus.)
IIRC, I explained this to someone with a name
similar to OP's last decade.
James