Bug #60786 [Com]: Force seeding to srand different numbers still gives the same random number
| From: | phpmpan at mpan dot pl | Date: | Wed, 18 Jan 2012 03:29:13 +0000 |
| Subject: | Bug #60786 [Com]: Force seeding to srand different numbers still gives the same random number | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-166575@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60786&edit=1
ID: 60786
Comment by: phpmpan at mpan dot pl
Reported by: jazzerman at gmail dot com
Summary: Force seeding to srand different numbers still gives
the same random number
Status: Open
Type: Bug
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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?
Previous Comments:
------------------------------------------------------------------------
[2012-01-17 23:06:36] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60786&edit=1