On March 2, 2010, I asked on Stackoverflow, “How can I store the state of the pseudo-random generator in Perl?”
At the time, the answer was “you can’t do that using the builtin pseudo random number generator.” Now, as I have mentioned before, using the builtin pseudo random number generator is fraught with traps regardless of language.
However, I was very happy to find out, via David Golden’s Lightning Talk slides (because I was too lazy to read the perldeltas first, I admit), that, as of Perl 5.13.4, srand
now returns the seed:
srand()
returns the seed so you can save it and call it again assrand($seed)
Nice!