php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60786 Force seeding to srand different numbers still gives the same random number
Submitted: 2012-01-17 23:06 UTC Modified: 2012-01-21 18:31 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jazzerman at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-01-17 23:06 UTC] jazzerman at gmail dot com
Description:
------------
srand( 822276816 );
$a = rand(123456, 987654);
echo $a;
echo "\n";
echo '822276816';
echo "\n";

srand( 561490788 );
$a = rand(123456, 987654);
echo $a;
echo "\n";
echo '561490788';
echo "\n";

Test script:
---------------
<?php 

srand( 822276816 );
$a = rand(123456, 987654);
echo $a;
echo "\n";
echo '822276816';
echo "\n";

srand( 561490788 );
$a = rand(123456, 987654);
echo $a;
echo "\n";
echo '561490788';
echo "\n";

?>

Expected result:
----------------
Since I'm seeding to srand different integers, it should echo two different 
random numbers.

Actual result:
--------------
It echos the same numbers even when seeding to srand two different integers

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-18 03:29 UTC] phpmpan at mpan dot pl
I see no reason to assume that two pseudorandom sequences don't contain common values. "Random" doesn't mean that values in a single sequence or a set of sequences can't repeat. In fact it's perfectly normal and expected that the do share some elements. Othwerwise they would not be pseudorandom anymore.

I must admit, however, that you're quite lucky guy. Finding by accident two different sequences that share a common element at the same position and, what's more interesting, it is the first element. What made you selecting 822276816 and 561490788 as the seeds?
 [2012-01-18 05:53 UTC] anon at anon dot anon
I get this:

898434
822276816
351663
561490788

(Windows/PHP 5.3.2)
 [2012-01-18 06:17 UTC] phpmpan at mpan dot pl
With 5.3.9 on Arch64 I'm getting 266557046 in both cases. Pair 53923 and 40348 causes the same bahaviour. And I believe there are many more. But none of this cases indicate a problem. It's normal that values are repeating in sequences.
 [2012-01-21 18:31 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2012-01-21 18:31 UTC] rasmus@php.net
Yes, no bug here. There are plenty of seeds that lead to the same initial random 
number. You will notice, however, that the second number in the sequence is 
different across the 2 seeds.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC