in reply to Can I seed srand() with results from rand()?
If rand() is a linear congruential generator (usually the case) with modulus $M, then thissrand( rand($M) )
is likely to be almost equivalent to calling rand() once or twice. Not quite, because there might be extra magic in srand(), and some rand()s only return 15 bits of randomness (even though they're seeded with 31). You might not care about having your entropy reduced to that, so go ahead with your plan. Otherwise, look into an alternate PRNG that gives you access to its internal state, like Math::Random.
What you want to avoid is using a seed with an obvious pattern in a loop. This is bad:srand( $n += 42 )
And keep in mind that more things have obvious patterns than you might think.
|Replies are listed 'Best First'.|
Re: Re: Can I seed srand() with results from rand()?
by no_slogan (Deacon) on Jul 10, 2003 at 05:53 UTC
by no_slogan (Deacon) on Jul 12, 2003 at 01:20 UTC