#20793 [Opn]: big selection with array_rand() works bad EVEN with srand()

2002-12-03 Thread msopacua
 ID:   20793
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Open
 Bug Type: Arrays related
 Operating System: Linux (redhat6.2) 2.2.14-5.0smp
 PHP Version:  4.2.3
 New Comment:

Here's something to test properly:
\n" :
"\n";

print("$string$nl");
}

$bricks = (isset($argv[1])) ? $argv[1] : 1;
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() * 1000);
$brickArray2 = array_rand($brickArray, sizeof($brickArray));
for($i=0;$i {$brickArray2[$i]}");
}
?>

I can't reproduce it - in fact, the following quick-hack-shell-tester
doesn't yield any output:
#!/bin/ksh

typeset -i COUNTER=1

while [ $COUNTER -lt 100 ]; do
./test_array_rand.php 3 | awk '{print $3}' | sort | perl -n -e
'print if $_ eq $previous; $previous=$_'
COUNTER=`expr ${COUNTER} + 1`
done

You should probably look at the query, rather than at rand. But then
again - if the above yields output, report back.


Previous Comments:


[2002-12-03 11:35:19] [EMAIL PROTECTED]

I will test the snapshot this weekend, I have no access to a test
machine earlier

Ps, array_rand($brickArray, sizeof($brickArray)-3);
should be array_rand($brickArray, sizeof($brickArray));,
the error occur with both! Ds



[2002-12-03 11:28:27] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip





[2002-12-03 11:24:16] [EMAIL PROTECTED]

http://www.arthistory.cc/info.php for my php info



[2002-12-03 11:21:49] [EMAIL PROTECTED]

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() * 1000);
srand ((float) microtime() * 100);

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() * 1000);
$brickArray2 = array_rand($brickArray, sizeof($brickArray)-3);
for($i=0;$ihttp://bugs.php.net/?id=20793&edit=1




#20793 [Opn]: big selection with array_rand() works bad EVEN with srand()

2002-12-03 Thread dave
 ID:   20793
 User updated by:  [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Open
 Bug Type: Arrays related
 Operating System: Linux (redhat6.2) 2.2.14-5.0smp
 PHP Version:  4.2.3
 New Comment:

http://www.arthistory.cc/info.php for my php info


Previous Comments:


[2002-12-03 11:21:49] [EMAIL PROTECTED]

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() * 1000);
srand ((float) microtime() * 100);

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() * 1000);
$brickArray2 = array_rand($brickArray, sizeof($brickArray)-3);
for($i=0;$ihttp://bugs.php.net/?id=20793&edit=1