Monday, October 4, 2010

Perl's srand now returns the seed

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 as srand($seed)

Nice!

1 comment:

  1. I cover the interesting, stand-out new features in The Effective Perler. I haven't said anything about srand yet because I haven't come up with something that's more than a couple of paragraphs. :)

    ReplyDelete