|Problems? Is your data what you think it is?|
Predictable random sequenceby vsespb (Hermit)
|on Sep 17, 2013 at 13:36 UTC||Need Help??|
vsespb has asked for the
wisdom of the Perl Monks concerning the following question:
I need to get predictible integer random number sequence (for use in unit tests).
Sequence should be strictly same on each run. It does not have to be really random (nor secure random of course)
Seems it's docummented that I can use srand() for this:
However, there are a few situations where programs are likely to want to call srand. One is for generating predictable results, generally for testing or debugging. There, you use srand($seed), with the same $seed each time.So I wrote the following code:
to get rid of possible float off-by-0.0000...00001 problems.
1. Will this work as expected? On each and every possible perl build and platform?
2. Is there a better way to do it?