php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37528 rand() weakness
Submitted: 2006-05-19 20:26 UTC Modified: 2006-05-19 21:00 UTC
From: lunter at interia dot pl Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.1.4 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lunter at interia dot pl
New email:
PHP Version: OS:

 

 [2006-05-19 20:26 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-19 20:35 UTC] lunter at interia dot pl
e.g. MatLab rand() generate perfect noise.
 [2006-05-19 20:37 UTC] pajoye@php.net
Use mt_rand if you want better random values.
 [2006-05-19 20:49 UTC] lunter at interia dot pl
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.
 [2006-05-19 20:54 UTC] pajoye@php.net
They are system dependent, it is not a php problem. Now please keep this bug as bogus and read the manual. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC