in reply to Re: Legacy code uses "srand()" .. how to avoid losing entropy?
in thread Legacy code uses "srand()" .. how to avoid losing entropy?
Which I believe is what you’re looking for.I don't think so. Suppose he'd captured the seed, then what? This is certainly not what he want:
Now $random1 and $random2 are the same.sub func() { srand $CONSTANT; ... do stuff using a known sequence ... } my $seed = srand; my $random1 = rand; func(); srand $seed; # Get back to "random" sequence again? my $random2 = rand;
You'd have to keep track of how many random numbers one has generated, and each time you'd call srand with the original seed again, you'd have to call rand that times, discarding the result before continuing.
|
|---|