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

In the distant past, I've wrapped pseudo-random-number generators in objects (this was in C++) and provided for different instances to exist with their own state data.

I had stuff that needed to repeat and not be thrown off by other uses of random, so it used its own instance for the purpose.

You want to simulate that without changing the line-by-line uses, by saving/restoring the global: Well, if the built-in srand is not accessible, use Perl techniques to replace the core::srand or a per-module view of srand to call your code, which does allow such a thing to be done. Better yet, have the srand replacement be a call to the object version so you can replace old-style calls with new ones incrementally without changing the sequence generated.

  • Comment on Re: Legacy code uses "srand()" .. how to avoid losing entropy?