Mail Archives: djgpp/1994/03/12/16:57:46
According to Murle C. Meetze III:
-} >My only remaining problem is with rand(), which always seems to return the
-} >same sequence. Usually there is an initialization routine, but I can't find
-} >it yet.
-}
-} I am not sure if you know. From what I am hearing I think
-} that you know about it. But of the rand() functions I have
-} seen most are pseudo-random number generators. Meaning if you
-} have a program that prints out 10 random numbers, ever time
-} you run it you will get the same thing. It usually has a
-} function known as a seed or like you said an initialization
-} function which starts the random number generator. I haven't
-} workied with the rand() function on gcc yet, so I can't tell
-} you what the name of the function is.(the init. one)
If you use rand() then you use srand(int) to initialize it. If you pass the
same number: srand(42) every time, it will always generate the same sequence
of numbers. A real good way to get a different sequence every time is to
use "srand(time());" to initialize it.
BTW, in GCC there is a better random number generator: random. It is the
same to use it, with "srandom()" being the initializer.
-------------------------------------------------------------------------------
Eric Eisenhart/Dr. Fish/Flourescent Floral Flouride <eric AT nermal DOT santarosa DOT edu>
Fortune of the day:
A little inaccuracy sometimes saves tons of explanation.
-- H. H. Munroe
-------------------------------------------------------------------------------
- Raw text -