PHP rand()与random_int() [英] PHP rand() vs. random_int()

查看:1543
本文介绍了PHP rand()与random_int()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

php.net表示: random_int()函数生成密码安全的伪随机整数.

但是,有人可以解释rand()和& amp;之间的区别吗? random_int()?仅需要随机整数时,可以使用random_int()代替rand()吗?哪一个更快?

But, Can someone explain whats the difference between rand() & random_int()? Can I use random_int() instead of rand() when only requiring a random integer? Which one is faster?

推荐答案

重新查看问题并看到给出了答案,我发现我将自己的评论提交给答案,并且认为之前已经提交过,这是很公平的.

Revisiting the question and seeing there's been an answer given, I find it's only fair that I submit my comments to an answer, seeing they were submitted before.

有关PHP 7 random_int()函数的手册指出:

The manual on PHP 7's random_int() function states:

返回介于min到max之间(包括端值)的加密安全随机整数."

  • http://php.net/manual/en/function.random- int.php
    • http://php.net/manual/en/function.random-int.php
    • rand()

      *此函数不会生成加密安全值" *

      *This function does not generate cryptographically secure values" *

      • http://php.net/manual/en/function.rand.php
        • http://php.net/manual/en/function.rand.php
        • OP的评论:

          "@ Fred-ii-谢谢.但是,加密安全的伪随机"是什么意思?– NDFA"

          根据我的发现,可以在以下链接中找到

          That can be found in the following links as per my findings:

          哪个州:

          密码安全的伪随机数生成器(CSPRNG)或密码伪伪随机数生成器(CPRNG)[1]是伪随机数生成器(PRNG),其属性使其适合用于密码学


          • 加密安全的随机数生成器如何工作?

            • How does a cryptographically secure random number generator work?
            • 关于性能,您需要自己运行基准测试.

              In regards to performance, you will need to run a benchmark yourself.

              这篇关于PHP rand()与random_int()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆