php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45302 rand() after array_rand() produces the same numbers
Submitted: 2008-06-18 17:08 UTC Modified: 2008-07-02 11:47 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sv4php at fmethod dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
 [2008-06-18 17:08 UTC] sv4php at fmethod dot com
Description:
------------
This was discovered by another guy who asked me to verify it on my configuration (and I confirmed it). I'm not sure he reported it, so just in case I do as well.

The example source code produced 989, 377, 989, 377 from rand() ad infinitum under Windows XP, Apache 2.2, PHP 5.2.6.

Important:

- Linux apparently not affected.
- mt_rand() apparently not affected.

Reproduce code:
---------------
function RandomNumber() {
	$f1 = array();

	for ($i = 0; $i < 50000; $i++) {		
		$f1[] = true;
	}	
			
	$k = array_rand($f1);
	
	$rnum = rand(1,999);	
	
	return $rnum;
}

for ($i = 0; $i < 20; $i++) {
	
	echo RandomNumber()."\n"; // produces a sequence of 377, 989, 377, 989, 377, 989, 377...  here
}

Expected result:
----------------
Random numbers.

Actual result:
--------------
Same number or narrow repeated sequence.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-02 11:47 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #45301
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 03 20:01:28 2024 UTC