#37528 [Opn->Bgs]: rand() weakness

From: Date: Fri, 19 May 2006 20:37:37 +0000
Subject: #37528 [Opn->Bgs]: rand() weakness
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-97386@lists.php.net to get a copy of this message
ID: 37528 Updated by: pajoye@php.net Reported By: lunter at interia dot pl -Status: Open +Status: Bogus Bug Type: Math related Operating System: WinXP PHP Version: 5.1.4 New Comment: Use mt_rand if you want better random values. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#97386) next »