Mail Archives: djgpp/1997/11/25/07:31:15
On Mon, 24 Nov 1997 19:31:21 -0600 in comp.os.msdos.djgpp Tony O'Bryan
<aho450s AT nic DOT smsu DOT edu> wrote:
: You can seed the random number generator with the current time like
: this:
: #include <time.h>
: #include <stdlib.h>
: int main(void)
: {
: srandom(time(NULL)); <-- this is the important line
: }
... but note that this seeds the `random()' generator. To seed the
`rand()' generator, use `srand' instead of `srandom'.
Also note that if you're from a Borland background you'll be expecting
the `random' function to take a parameter (the smallest integer that
will never be returned) -- in djgpp this is not the case. The `rand'
function returns an integer from 0 to RAND_MAX and the `random'
function returns an integer from 0 to MAXINT. In practice, these
maxima are both the same, and equal to the largest number that can be
expressed as a (32-bit) integer. To restrict the range of the
numbers, use the divison-remainder operator, `%'.
--
Regards,
george DOT foot AT merton DOT oxford DOT ac DOT uk
- Raw text -