(Gordon Burditt) writes:
[...]
> It is possible to cripple a really good pseudo-random number generator
> with a poor seed. If you use a really good one that won't repeat
> within 2**1024 lifetimes of the universe, and seed it with a 16-bit
> number, all I have to do is try the 65,536 combinations of the seed.
> Note that some versions of rand() only accept a 16-bit number (and
> perhaps use only 15 bits of it). RAND_MAX is only required to be
> at least 32767, so you might be seeding random() with a 15-bit
> number.
[...]
RAND_MAX is the maximum value that rand() will return; it's at
least 32767 and at most INT_MAX.
The argument to srand() is of type unsigned int, so the maximum
seed value is UINT_MAX, not RAND_MAX.
An implementation might have RAND_MAX==32767, but accept 32-bit
seeds and generate 2**32 distinct sequences of 15-bit pseudo-random
numbers. (It could also accept 32-bit seeds and ignore all but 16
bits, or even fewer.)
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"