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

发布于 2024-12-27 01:28:02 字数 227 浏览 6 评论 0原文

我想在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜柠檬 2025-01-03 01:28:02

如果您需要可重复的行为,您应该使用 srand()mt_srand()< 自行播种 rand()mt_rand() /code> 并存储您使用的种子。

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.

黑凤梨 2025-01-03 01:28:02

据我所知,了解所使用的种子是什么的唯一方法是自己指定它

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

十年九夏 2025-01-03 01:28:02
mt_srand($known_value)

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

mt_srand($known_value)

Will set your seed to a repeatable value

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文