如何从 PHP 中的随机数生成器获取种子值
我想在使用 rand()
或 mt_rand()
后获取种子值。本质上,我想存储种子,以便下次执行 php 时可以使用该种子继续生成随机数。
我需要一个可重复的行为来进行单元测试/负载测试......并且我的应用程序中的不同模块将使用相同的种子,以便生成的随机数序列是可再现的。
感谢您的意见。我找不到获得种子的方法。公开种子的随机数生成器类也会很有帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您需要可重复的行为,您应该使用
srand()
或mt_srand()< 自行播种
rand()
或mt_rand()
/code> 并存储您使用的种子。If you need repeatable behavior, you should seed
rand()
ormt_rand()
yourself usingsrand()
ormt_srand()
and store the seed that you use.据我所知,了解所使用的种子是什么的唯一方法是自己指定它。
AFAIK the only way to know what the seed in use is is to specify it yourself.
会将您的种子设置为可重复的值
Will set your seed to a repeatable value