From:             cetra3 at hotmaill dot com
Operating system: Windows XP
PHP version:      5.2.4
PHP Bug Type:     *Math Functions
Bug description:  rand generates predictable results

Description:
------------
The function Rand will produce predictable results.

Reproduce code:
---------------
<?php

$array_random = array_fill(1,10,1);

for($i=0;$i<100000000;$i++) {

$array_random[rand(1,10)]++;

}

print_r($array_random);

?>

Expected result:
----------------
This should produce an array which counts how many times each number is
picked at random.  It should return a different result each time.

Actual result:
--------------
Instead of getting purely random responses, we get predictable ones, in
this example there will be tainted results, with numbers 5 and 10 producing
lower counts:

Array
(
    [1] => 10000594
    [2] => 10000610
    [3] => 10000633
    [4] => 10000589
    [5] => 9997562
    [6] => 10000606
    [7] => 10000568
    [8] => 10000620
    [9] => 10000645
    [10] => 9997583
)

You will always see these types of return values.

-- 
Edit bug report at http://bugs.php.net/?id=43108&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43108&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43108&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43108&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43108&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43108&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43108&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43108&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43108&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43108&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43108&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43108&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43108&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43108&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43108&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43108&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43108&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43108&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43108&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43108&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43108&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43108&r=mysqlcfg

Reply via email to