Archived from groups: rec.games.roguelike.development (
More info?)
"Krice" <paulkp@mbnet.fi> writes:
> Jeff Lait wrote:
> > On MSVC, RAND_MAX is 32768.
> > I shouldn't need to say more.
>
> Well, I don't know what that means
If you call rand() you get a number between 0 and RAND_MAX (or
RAND_MAX-1, perhaps).
Most of the time, RAND_MAX is 2**31 (ish).
Effects of this:
Any chance below 1/32768 will either map to 0 or 1/32768, depending on
the precise algorithm. This could end up quite skewed.
Because rand() is cyclic and deterministic, your cycle time is only
32768. This can cause problems when doing sequential random
numbers. For example, say a humanoid creature has a 0.1% chance of being
generated with a random wand that it knows how to use.
There will be ~32 numbers that rand() could have produced that would
do that. Say that it then selects the wand type from 1d100 on this list:
1-10: light
11-20: darkness
....etc...
97: death ray
98: earthquakes
99: disintegration
100: ultimate doom
There are only ~32 numbers that could have led to the wand being
created. Since each of those numbers has a definite successor, there
are therefore only 32 possible outcomes of the d100 roll that can
actually happen (and the birthday paradox suggests that some of these
will be the same, which makes it even worse).
So it might be impossible to get a monster generated holding a wand of
earthquakes, or it might be a 3% chance rather than a 1% chance that
the wand is of ultimate doom, or other oddities.
So you'll get very odd situations occuring, possibly in a way that's
very bad for game balance, that never occurred when you compiled
against a better RNG.
There was a thread on rgrm not long back mentioning similar problems
with RAND_MAX on minGW being 32767.
--
Chris