www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/16/02:03:13

From: locke AT mcs DOT net (Peter Johnson)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: time() frequency
Date: Mon, 15 Nov 1999 23:25:04 -0600
Organization: BiLogic Productions
Lines: 32
Message-ID: <MPG.129aa6abee0bc9a29896c3@news.cso.uiuc.edu>
References: <FL8wAt DOT 2GG AT freenet DOT buffalo DOT edu> <83ogcv8lk2 DOT fsf AT mercury DOT st DOT hmc DOT edu> <FL9vH5 DOT D18 AT freenet DOT buffalo DOT edu>
NNTP-Posting-Host: isr4186.urh.uiuc.edu
X-Newsreader: MicroPlanet Gravity v2.12
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Your problem is that you should only call srand _once_, not every time 
you need a random number.  Once the generator is seeded, then it doesn't 
need to be seeded again and you can call rand() as rapidly as you want.  

You should only run into the below problem if your program is run (eg, 
restarted from the commandline) many times per second, in which case 
srand will be seeded by the same time value.

In article <FL9vH5 DOT D18 AT freenet DOT buffalo DOT edu>, co273 AT freenet DOT buffalo DOT edu 
says...
> Well, the problem is, I use DJGPP and the srand(time(0)); call to seed the
> random generator, while my collegue uses Borland C++ 5.0 and a randomize()
> function in his stdlib.h...After I chewed him out for using a propietary
> non-standard function to seed the random number, I pointed out that while
> using the DJGPP srand(time(NULL)) call, the random function if called in
> very rapid succession would yield preictable results, while using
> rawclock() (18.2 ticks/sec) would yield marginally better
> results...however, he claims that time() works in the Microsecond level
> and should not return predictable random results...
> The problem is...I tested the code in DJGPP and MSVC6 and they both yeild
> precdictable results if the program is run in less than 1 seconds of
> time...While I did not test the Borland Code (Because I don't have
> Borland, and the Borland code won't compile under DJGPP) I cannot say for
> sure whether my collegue's right (Well, partly right...Perhaps Borland's 
> C++ 5 does have a Microsecond level time() function) or I'm right (That
> all time() functions for x86 machines run on the Second level)

-- 
Peter Johnson             locke AT mcs DOT net
:Windows: Where do you want to go today?
:Linux:   Where do you want to go tomorrow?
:FreeBSD: Are you guys coming or what?

- Raw text -


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