Mail Archives: djgpp/1998/05/31/22:16:48
What i did, which was probably a bit of overkill in guaranteeing
randomness, was seed the number a bunch of times during initialization
it looks like this:
uclock() // to start timing
for (i = 0; i <= 4 ; i++){
for (i = rand() % 2000; i >= 1600 ; i--);
srand(uclock() + biostime());
}
i know that it is probably incredibly inefficient and bad coding and
all of that crap, but it seeds the number generator rand() pretty well
:)
Nate Eldredge wrote:
>
> At 05:32 5/26/1998 -0500, Jason Cain wrote:
> >Hello,
> >
> >I'm trying to generate a sequence of random numbers, so I wrote a simple
> >program to generate 20 random numbers as a test. I'm using the
> >srandom() function with a seed value generated by rawclock(). I thought
> >this might be a good way to generate a different seed every time.
> >However, rawclock() seems to be returning zero every time, which causes
> >me to get the same sequence of random numbers every time. Can anyone
> >offer any suggestions on what I'm doing wrong or alternate methods? I'm
> >using Windows NT4--perhaps that has something to do with it? Short code
> >follows.
>
> `rawclock' is buggy in the current version. Presently, it actually returns
> the number of clock ticks since it was first called. In v2.02, it will work
> like the documentation says.
>
> You could use `time(NULL)' instead, which is also more portable (ANSI). If
> you expect to run your program more than once a second, you could use the
> `tv_usec' field returned by `gettimeofday', which is POSIX. See the docs.
>
> Nate Eldredge
> nate AT cartsys DOT com
--
"A good american must practice bad Americanism." -Black Like Me
Ryan Bank O/ Disco Inferno !!
axle AT earthlink DOT net /\ Burn, baby burn!!!
Laguna Niguel, CA /> Disco all night!
Pursuant to US Code, Title 47, Chapter 5, Subchapter II, B227, any and
all nonsolicited commercial e-mail sent to this address is subject to a
download and archival fee in the amount of $500 US. E-mailing denotes
acceptance of these terms.
- Raw text -