PHP的随机播放功能随机性如何?

编程入门 行业动态 更新时间:2024-10-27 02:24:06
本文介绍了PHP的随机播放功能随机性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人知道PHP shuffle()函数的随机性是什么吗?是否取决于操作系统? 它使用PHP自己的播种器吗?

Does anyone know what's the randomness of PHP's shuffle() function? Does it depend on the operating system? Does it use PHP's own seeder?

是否可以使用mt_rand()作为生成器?

Is it possible to use mt_rand() as generator?

推荐答案

shuffle()函数基于与rand()相同的生成器,后者是基于线性同余算法.这是一个快速生成器,但具有或多或少的随机性.从PHP 4.2.0开始,随机生成器会自动生成种子,但是如果需要,您可以使用srand()函数对其进行种子植入.

shuffle() function is based on the same generator as rand(), which is the system generator based on linear congruential algorithm. This is a fast generator, but with more or less randomness. Since PHP 4.2.0, the random generator is seeded automatically, but you can use srand() function to seed it if you want.

mtrand()基于 Mersenne Twister算法,它是最好的伪代码之一.可用的随机算法.要使用该生成器对数组进行混洗,您需要编写自己的混洗函数.例如,您可以查看 Fisher-Yates算法.编写自己的随机播放功能会产生更好的随机性,但会比内置随机播放功能慢.

mtrand() is based on Mersenne Twister algorithm, which is one of the best pseudo-random algorithms available. To shuffle an array using that generator, you'd need to write you own shuffle function. You can look for example at Fisher-Yates algorithm. Writing you own shuffle function will yield to better randomness, but will be slower than the builtin shuffle function.

更多推荐

PHP的随机播放功能随机性如何?

本文发布于:2023-10-28 08:16:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:随机性   功能   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!