简体   繁体   English

PHP何时会为mt_rand()生成种子

[英]When will PHP generate the seed for mt_rand()

will PHP generate the seed (that is used in mt_rand()) when the server will be restarted? 重启服务器时,PHP将生成种子(在mt_rand()中使用)吗? Where does PHP store this value? PHP在哪里存储此值?

I just found out that mt_rand() is not safe, and try to create a proof of concept for it. 我刚刚发现mt_rand()不安全,并尝试为其创建概念证明。

Thank you very much! 非常感谢你!

mt_rand() is automatically seeded the first time it is used within a request , with a seed that is based on the PID, the current timestamp, and PHP's internal LCG (Linear Congruent Generator).... you can override this at any point in script execution using mt_srand() to reseed using your own seed. mt_rand() 在请求中首次使用时会自动播种,其播种基于PID,当前时间戳和PHP的内部LCG(线性一致生成器)。...您可以在任何时候覆盖它使用mt_srand()在脚本执行中使用自己的种子进行种子设定。

Note that mt_rand() is not considered suitable for cryptographic applications, as stated in the PHP Docs . 请注意,如PHP Docs中所述,mt_rand()不适合加密应用程序。 If you want crypto-strength randomness, use a documented crypto-strength generator. 如果您希望加密强度随机性,请使用已记录的加密强度生成器。

I just found out that mt_rand() is not safe, and try to create a proof of concept for it. 我刚刚发现mt_rand()不安全,并尝试为其创建概念证明。

See php_mt_seed by OpenWall. 参见OpenWall的php_mt_seed

If you want an alternative: 如果您想要替代方法:

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

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