Coder's Guild Mailing List

RE: Seeding random number generators (was: Re: using rand for cplus)

Posted by RayG In Greece on 1999-10-07

Hi..
Had the same prb with srand/rand myself.
However,(even tho i havent tried it myself)
sb told me what i could do if i really needed
to run srand() more than once every second (typical of
fast loops).
You could do smth like this(pseudo-code):
void main (void ){
srand(getcurrenttime());
int a;
for( ){   //startofloop
a=rand();
do_whatever_u_want();
srand(a);
}         //endofloop
};

so as u can see,u need to use srand(currenttime) only once
and then use the random nums u get to re-seed the RNG.
Regards,Ray-G

__________________________________________________
FREE Email for ALL! Sign up at http://www.mail.com