delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/25/07:31:15

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: randomize?
Date: 25 Nov 1997 05:28:49 GMT
Organization: Oxford University, England
Lines: 30
Message-ID: <65dnmh$1pk$3@news.ox.ac.uk>
References: <b187cd$10393b DOT 109 AT news DOT alberni DOT net> <347A2A69 DOT 73DE AT nic DOT smsu DOT edu>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019