delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/05/18:09:31

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random numbers/George
Date: Thu, 05 Jun 1997 12:00:32 -0400
Organization: Cornell University
Lines: 46
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <3396E2A0.C57@cornell.edu>
References: <2 DOT 2 DOT 32 DOT 19970604162434 DOT 0069d50c AT gate> <3395B097 DOT 5077 AT cornell DOT edu> <33967eab DOT 25749893 AT supernews DOT scsn DOT net>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: 128
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Chris wrote:
> 
> Here is a bit of code from C for Dummies.  The book is terrible in
> most parts, but this is a nice llittle thing it did.  It demonstrates
> how to go about generating random numbers using the computers time.
> 

ok, given the reference, it should not be surprising that you do not
know the difference between seeding a random number generator and the
actual algorithm that generates the pseudo-random numbers. a random
number generator is actually a deterministic algorithm. that is, if you
give it the same seed, you will get the same sequence out of it each and
every time. this is actually very desirable for scientific applications.
however, when you are playing a game, you do not want your hero to start
at the same corner all the time. so, seeding the rng eith the ticks
serves the purpose of giving the rng a non-predetermined starting point
every time, and produce a different series every time.

> 
> int rnd(int range);
> int seedrnd(void);

what is the point of this? first, your declaration does not match the
actual function. second, why do something that is essentially renaming a
standard library function.

> 
> void main(void)

no. int main(void) or int main(int argc, char *argv[]).

> int rnd(int range)
> {
>         int r;
>         r=rand()%range;
>         return(r);
> }
> 

the question is whether % preserves the 'statistical randomness' of the
series generated by rand().

this has been answered in detail before. read those posts and, please,
for do not quote any dummies book.

  -- Sinan.

- Raw text -


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