reproducible random number series

后端 未结 3 2071
心在旅途
心在旅途 2021-02-20 10:10

How can i get a series of reproducible pseudorandom numbers in PHP?

In older versions of PHP i could do that just by using the same seed in the RNG, but it does not work

3条回答
  •  礼貌的吻别
    2021-02-20 10:59

    One of the best random number algorithms by some metrics is Mersenne Twister. You can find a pure PHP version here (there are others).

    You can then call:

    init_with_integer($integer_seed)
    

    and get the same output (for a given seed) every time.

提交回复
热议问题