in reply to Legacy code uses "srand()" .. how to avoid losing entropy?

I observe that srand() merely returns “1.”
According to Perl 5.14’s perlfunc entry for srand:
The point of the function is to “seed” the rand function so that rand can produce a different sequence each time you run your program. When called with a parameter, srand uses that for the seed; otherwise it (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, it returns the seed.

Which I believe is what you’re looking for.

Replies are listed 'Best First'.
Re^2: Legacy code uses "srand()" .. how to avoid losing entropy?
by JavaFan (Canon) on May 04, 2011 at 00:22 UTC
    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:
    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;
    Now $random1 and $random2 are the same.

    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.