2

I would like to get the seed value after the rand() or mt_rand() is used. Essentially I want to store the seed so that I can use this seed to continue generating random numbers next time php is executed.

I need a repeatable behavior for unit testing/load testing... and different modules in my applications will use the same seed, so that the sequence of random numbers are generated are reproducible.

Thanks for your input. I couldn't find a method to get the seed. A Random number generator class that exposes the seed would be helpful too.

favo
  • 5,426
  • 9
  • 42
  • 61

3 Answers3

2

If you need repeatable behavior, you should seed rand() or mt_rand() yourself using srand() or mt_srand() and store the seed that you use.

FtDRbwLXw6
  • 27,774
  • 13
  • 70
  • 107
2

AFAIK the only way to know what the seed in use is is to specify it yourself.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
1
mt_srand($known_value)

Will set your seed to a repeatable value

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92