php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25639 problem with rand()
Submitted: 2003-09-23 18:21 UTC Modified: 2003-10-09 06:06 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: adamm at nycap dot rr dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.3.3 OS: windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: adamm at nycap dot rr dot com
New email:
PHP Version: OS:

 

 [2003-09-23 18:21 UTC] adamm at nycap dot rr dot com
Description:
------------
I am developing on a newly setup Windows XP Box running PHP 4.3.3 on IIS as CGI.

The rand() function is not generating random numbers. Even with a min/max declared it will only once generate a number in that range... and than any other time called (even across browser sessions) it will always and forever generate the same number.

The code below is broken down to the smallest example possible.

Reproduce code:
---------------
<?php
echo rand();
?>

Expected result:
----------------
I expect to see a random number.

Actual result:
--------------
The same number is always displayed.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-23 18:37 UTC] adamm at nycap dot rr dot com
I downgraded to 4.3.2 and I dont have this problem. I also found several posts on the net about many people on Win XP having this problem with 4.3.3.

Definate bug id say.
 [2003-09-23 22:29 UTC] iliaa@php.net
Does this happen if you call srand() prior to calling the rand() function?
 [2003-10-08 09:30 UTC] paul dot vaughan at weston dot ac dot uk
I was having this problem (PHP 4.3.3 on WinNT 4) but in response to iliaa@php.net's question, the function 'srand()' does indeed fix the problem.

The code:
for ($j=1; $j<10001; $j++) {
   print (rand(0, $j)."<br>");
}
...produced the same ten thousand random numbers each and every time. Putting srand() before the loop stopped this happening.

I hope this info is useful to someone; not sure anyone will read this...!

Vaughany.
 [2003-10-09 06:06 UTC] sniper@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 21:01:33 2025 UTC