Edit report at https://bugs.php.net/bug.php?id=60786&edit=1
ID: 60786
Comment by: anon at anon dot anon
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 get this:
898434
822276816
351663
561490788
(Windows/PHP 5.3.2)
Previous Comments:
------------------------------------------------------------------------
[2012-01-18 03:29:13] 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-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