Mail Archives: djgpp/2000/05/25/01:50:19
On Thu, 25 May 2000, Chris Miller wrote:
> If RAND_MAX is set to 100, then a call to rand() should return an
> integer between 0 and 100. However, on my computer, a call to rand()
> generates a number between what appears to be hundreds of millions and
> 0, even with RAND_MAX set to 100.
You cannot control `rand' by setting RAND_MAX, it is a constant that
tells you what is the range of numbers produced by `rand'. Changing its
value will have no effect, since when `rand' was compiled, it used the
original value.
The recommended way to generate random numbers from a smaller range is
described in section 22.23 of the DJGPP FAQ list, which see.
- Raw text -