gpt4 book ai didi

PHP rand() 与 random_int()

转载 作者:IT王子 更新时间:2023-10-29 00:12:07 25 4
gpt4 key购买 nike

作为php.net indicates: random_int() 函数生成加密安全的伪随机整数

但是,有人可以解释一下 rand()random_int() 之间的区别吗?当只需要一个随机整数时,我可以使用 random_int() 而不是 rand() 吗?哪个更快?

最佳答案

重新审视这个问题并看到已经给出了答案,我发现我将我的评论提交给答案是公平的,因为他们之前已经提交过。

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

"Returns a cryptographically secure random integer in the range min to max, inclusive."

rand()

*This function does not generate cryptographically secure values" *

OP 的评论:

"@Fred-ii- thank you. But what does "cryptographically secure pseudo-random" mean? – NDFA"

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

其中指出:

A cryptographically secure pseudo-random number generator (CSPRNG) or cryptographic pseudo-random number generator (CPRNG)[1] is a pseudo-random number generator (PRNG) with properties that make it suitable for use in cryptography.


关于性能,您需要自己运行基准测试。

关于PHP rand() 与 random_int(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44228718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com