From: [EMAIL PROTECTED]
Operating system: Linux (redhat6.2) 2.2.14-5.0smp
PHP version: 4.2.3
PHP Bug Type: Arrays related
Bug description: big selection with array_rand() works bad EVEN with srand()
I use array_rand() to randomize an array that can have three different
sizes, 450, 800 and 1152. With 450 array_rand works great. But when I try
to select 800 and 1152 indexes with array_rand(), array_rand seems to seed
higher number. I everycase I always get the 25 last indexes picked! Pretty
weird! It seems to favor the last number!
I have tried:
srand ((float) microtime() * 10000000);
srand ((float) microtime() * 1000000);
But that didn't helped:
Here's my code:
if($bricks==1) $tempArrValue=450;
if($bricks==2) $tempArrValue=800;
if($bricks==3) $tempArrValue=1152;
$brickArray = array();
for($i=1;$i<=$tempArrValue;$i++){
$brickArray[$i]=$i;
}
srand ((float) microtime() * 10000000);
$brickArray2 = array_rand($brickArray, sizeof($brickArray)-3);
for($i=0;$i<sizeof($brickArray2);$i++){
mysql_query("insert into puzzle_bricks values(0,$countryIndex,$i, " .
$brickArray2[$i] . ");");
}
My conclusion is that their are some problems when seeding random numbers
for array_rand when you are selecting an array with more than 800 indexes
as output.
I mean I have solved the issue by making my own array_rand function, but I
just wanted to help makeing PHP a better product.
Best Regards Dave,
Ps, I love PHP, Ds
--
Edit bug report at http://bugs.php.net/?id=20793&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20793&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20793&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20793&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20793&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20793&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20793&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20793&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20793&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20793&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20793&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20793&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20793&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20793&r=isapi