G
Gordon Burditt
Now my suggestion is to use the (normally pitiful) built in rand
The number of possible shuffles of a deck of cards is 52 factorial.
Any seed less than 200 bits long is pitifully inadequate, especially
if you're playing for real money.
By using the built in rand() to generate a seed, you are potentially
crippling the Mersenne Twister (which only has 31 bits of seed,
still horribly inadequate, but probably generates much better random
numbers than rand()) with something which may only generate 2**15
possible seeds.
This approach does nothing to increase the number of possible shuffle
results beyond the number of seeds that srand() accepts.
This would increase the number of possible shuffles *IF* you don't
start the program over again each time, but just continue from
the previous state of the Twister.
Gordon L. Burditt
and srand functions to produce one random value, and use the
result to seed the Mersenne Twister (with seedMT()). You could
The number of possible shuffles of a deck of cards is 52 factorial.
Any seed less than 200 bits long is pitifully inadequate, especially
if you're playing for real money.
By using the built in rand() to generate a seed, you are potentially
crippling the Mersenne Twister (which only has 31 bits of seed,
still horribly inadequate, but probably generates much better random
numbers than rand()) with something which may only generate 2**15
possible seeds.
then use another value from rand to clock the twister through a
semi-random number of initial values, and continue from there.
Something like:
unsigned long count;
srand(time(NULL));
seedMT((unsigned long)rand() & ~1UL);
count = rand();
while (count--) randMT();
This only need to happen once, at program initialization, and can
be bypassed for a deterministic sequence for testing. After that
the shuffle can depend only on randMT. If initialization takes
too long limit the size of count.
This approach does nothing to increase the number of possible shuffle
results beyond the number of seeds that srand() accepts.
Notice that the period of the Mersenne Twister is much longer than
the maximum return value, which is ULONG_MAX. Thus duplicate
values CAN and will occur.
This would increase the number of possible shuffles *IF* you don't
start the program over again each time, but just continue from
the previous state of the Twister.
Gordon L. Burditt