#26290 [Com]: array_rand() not random

From: Date: Mon, 17 Nov 2003 17:26:00 +0000
Subject: #26290 [Com]: array_rand() not random
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50484@lists.php.net to get a copy of this message
ID: 26290 Comment by: scottm at spamcop dot net Reported By: alisovoi at hotmail dot com Status: Open Bug Type: Reproducible crash Operating System: Linux Redhat 9 PHP Version: 4.3.4 New Comment: 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>'; ?> Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#50484) next »