note 103009 added to function.rand
| From: | AlexKhimchalex at khim dot removeit dot ich dot org | Date: | Sat, 19 Mar 2011 21:41:33 +0000 |
| Subject: | note 103009 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178022@lists.php.net to get a copy of this message | ||
Random is NOT actually random.
It is easily illustrated by multiplying rand(1,500) by rand(1,500) and showing the output on the
image:
<?php
header("Content-type: image/png");
$img = imagecreatetruecolor(500,500);
$ink = imagecolorallocate($img,255,255,255);
for($i=0;$i<500;$i++) {
for($j=0;$j<500;$j++) {
imagesetpixel($img, rand(1,500), rand(1,500), $ink1);
}
}
imagepng($img);
imagedestroy($img);
?>
I expected to get pixel noise, but instead one can see plain diagonal lines.
----
Server IP: 213.186.192.247
Probable Submitter: 91.213.119.254
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/103009
Del: integrated -- https://master.php.net/note/delete/103009/integrated
Del: useless -- https://master.php.net/note/delete/103009/useless
Del: bad code -- https://master.php.net/note/delete/103009/bad+code
Del: spam -- https://master.php.net/note/delete/103009/spam
Del: non-english -- https://master.php.net/note/delete/103009/non-english
Del: in docs -- https://master.php.net/note/delete/103009/in+docs
Del: other reasons-- https://master.php.net/note/delete/103009
Reject -- https://master.php.net/note/reject/103009
Search -- https://master.php.net/manage/user-notes.php