ID: 26290 Comment by: scottm at spamcop dot net Reported By: alisovoi at hotmail dot com Status: Bogus Bug Type: Performance problem Operating System: Linux Redhat 9 PHP Version: 4.3.4 New Comment:
>From the array_rand documentation ----------- As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. Previous Comments: ------------------------------------------------------------------------ [2003-11-17 14:12:44] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You forgot to call srand() to generate random key. Hence the lack of random data. ------------------------------------------------------------------------ [2003-11-17 12:26:00] scottm at spamcop dot net Can't confirm under same OS. I used a easier test case. ----- <?php $random_sayings = array('Hey, this is not','randomly chosen','elements from an array'); $i = 0; echo '<pre>'; while ($i < 1000) { print $random_sayings[array_rand($random_sayings)] . "\n"; ++$i; } echo '</pre>'; ?> ------------------------------------------------------------------------ [2003-11-17 12:00:36] alisovoi at hotmail dot com Description: ------------ $array[array_rand($array)] is always the same element of the array. The server uses php.ini-recommended for the configuration. (In PHP 4.3.2, this problem is non-existant. PHP 4.3.4 has this bug) Reproduce code: --------------- <?php $random_sayings = array('Hey, this is not','randomly chosen','elements from an array'); echo($random_sayings[array_rand($random_sayings)]); ?> Expected result: ---------------- Either one of the 3 elements of the array. Actual result: -------------- The same element no matter how many times the user refreshes. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26290&edit=1
