php rand 不显示0,有可能在PHP中预测rand(0,10)吗?

rand()函数返回一个伪随机数。

这并不意味着可以预测下一个数字。

然而,这个图像可以解释伪随机的概念

你可以阅读这个article

该图像是从Windows系统上的带有rand函数的简单循环生成的。

header("Content-type: image/png");

$im = imagecreatetruecolor(512, 512) or die("Cannot Initialize new GD image stream");

$white = imagecolorallocate($im, 255, 255, 255);

for ($y = 0; $y < 512; $y++) {

for ($x = 0; $x < 512; $x++) {

if (rand(0, 1)) {

imagesetpixel($im, $x, $y, $white);

}

}

}

imagepng($im); imagedestroy($im);

这不是随机的吗?但现在你知道了吗?你可以预测下一个数字?

The difference between true random number generators (TRNGs) and pseudo-random number generators (PRNGs) is that TRNGs use an unpredictable physical means to generate numbers (like atmospheric noise), and PRNGs use mathematical algorithms (completely computer-generated)

[…]

Not many PRNGs will produce an obvious visual pattern like this, it just so happens to be a really bad combination of language (PHP), operating system (Windows), and function (rand()).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值