简体   繁体   English

如何从PHP中的随机数生成器获取种子值

[英]How to get the seed value from a random number generator in PHP

I would like to get the seed value after the rand() or mt_rand() is used. 我想在使用rand()mt_rand()之后获得种子值。 Essentially I want to store the seed so that I can use this seed to continue generating random numbers next time php is executed. 本质上,我想存储种子,以便下次执行php时可以使用该种子继续生成随机数。

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. 公开种子的随机数生成器类也将很有帮助。

如果您需要可重复的行为,则应使用srand()mt_srand()自己为rand()mt_rand()设置种子,并存储使用的种子。

AFAIK知道使用的种子的唯一方法是自己指定种子。

mt_srand($known_value)

将您的种子设置为可重复的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM