Does array_rand use the Mersenne Twister algorithm?

*爱你&永不变心* 提交于 2019-12-11 03:21:44

问题


In PHP, we have the choice of mt_rand() and rand() where mt_rand() uses the Mersenne Twister algorithm and rand() uses the libc random generator.

I would like to choose a random item out of an array using array_rand. However, does array_rand use the Mersenne Twister algorithm?

It is quite simple to implement my own array_rand using mt_rand, but if array_rand uses the Mersenne Twister, then all the better.


回答1:


It appears that array_rand uses php_rand() internally, which appears to be the good old non-mt version.




回答2:


It does now, as of PHP 7.1; see this RFC and this bug report for more details.




回答3:


It was probably not the case since results from array_rand() used to be not random at all. It's been fixed in latest releases (see Vaxquis's answer for the details).



来源:https://stackoverflow.com/questions/10101923/does-array-rand-use-the-mersenne-twister-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!