如何在
PHP中获得一系列可重现的伪随机数?
在旧版本的PHP中,我可以通过在RNG中使用相同的种子来实现,但是由于PHP已经改变了rand和mt_rand的工作方式,所以不再工作了.
Keep in mind that the Suhosin patch which is installed by default on
many PHP-installs such as Debian and DirectAdmin completely disables
the srand and mt_srand functions for encryption security reasons. To
generate reproducible random numbers from a fixed seed on a
Suhosin-hardened server you will need to include your own pseudorandom
generator code.
该评论的链接:http://www.php.net/manual/en/function.srand.php#102636
是否有任何解决方案准备好了?我没有时间和经验来创建我自己的伪随机生成器代码.
我的目标是要有一个代码
<?PHP //( pseudo random code here...) $the_seed = 123; // 123 is just a number for demo purposes,NOT a static number //...i hope you get the idea. It's just a hardcoded seed,// it could be a seed based on a user-id,a date etc... // we need the same output for a given seed. //( pseudo random code here...) // ...and finally echo $the_random_number; ?>
所以每次我访问这个页面,我应该得到相同的数字.
Mersenne Twist是一个很好的快速PRNG,这里是一个公共领域的PHP实现:
原文链接:https://www.f2er.com/php/133086.htmlhttp://kingfisher.nfshost.com/sw/twister/