php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11108 Problem in rand() on win2000 (or all win32?)
Submitted: 2001-05-25 04:02 UTC Modified: 2001-07-22 15:55 UTC
From: djewett at usd dot edu Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.5 OS: Windows 2000 SP2
Private report: No CVE-ID: None
 [2001-05-25 04:02 UTC] djewett at usd dot edu
// Sample code for problem	
srand(time());
for($counter = 0; $counter<= 20 ; $counter++){
print(rand(0,5 );
print("<br>");
}

for some reason this always returns the same number as the first number returned, until the file is modified.  The first number, after that, the numbers seem to be random.  

I'm using the latest apache & php on a win2k SP2 laptop

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-22 15:55 UTC] andy@php.net
try using a better seed for the random number, such as

srand((double) microtime() * 1000000);

this fixed the problem on my machine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 30 22:01:28 2024 UTC