Mail Archives: djgpp/1999/11/16/02:03:13
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 -