#37528 [Bgs->Opn]: rand() weakness
| From: | lunter at interia dot pl | Date: | Fri, 19 May 2006 20:49:31 +0000 |
| Subject: | #37528 [Bgs->Opn]: rand() weakness | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-97388@lists.php.net to get a copy of this message | ||
ID: 37528
User updated by: lunter at interia dot pl
Reported By: lunter at interia dot pl
-Status: Bogus
+Status: Open
Bug Type: Math related
Operating System: WinXP
PHP Version: 5.1.4
New Comment:
Sorry but..
run this script on Linux PHP - perfect noise
run this script on WinXP PHP - pattern!
WinXP rand() should be good like Linux rand()
Actually rand() is not the same.
Previous Comments:
------------------------------------------------------------------------
[2006-05-19 20:37:37] pajoye@php.net
Use mt_rand if you want better random values.
------------------------------------------------------------------------
[2006-05-19 20:35:01] lunter at interia dot pl
e.g. MatLab rand() generate perfect noise.
------------------------------------------------------------------------
[2006-05-19 20:26:41] lunter at interia dot pl
Description:
------------
rand() weakness.
example (reproduce code): rand generate pattern instead of noise
Reproduce code:
---------------
<?
$i=imagecreatetruecolor(1024,768);
for($y=0;$y<768;$y++){
for($x=0;$x<1024;$x++){
$c=rand(0,1)*255;
imagesetpixel($i,$x,$y,($c<<16)+($c<<8)+$c);
}
}
header('Content-type: image/png');
imagepng($i);
?>
Expected result:
----------------
noise
Actual result:
--------------
pattern
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37528&edit=1