note 33685 modified in function.array-rand by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:48:40 +0000 |
| Subject: | note 33685 modified in function.array-rand by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79762@lists.php.net to get a copy of this message | ||
The shuffle() routine works great, far better than array_rand(). Just one small change I'd
make, as mt_rand(0, 0) doesn't work:
<?php
$c = count($foo);
for ($i=1; $i<$c; $i++) {
$d = mt_rand(0, $i);
$tmp = $foo[$i];
$foo[$i] = $foo[$d];
$foo[$d] = $tmp;
}
?>
--was--
The shuffle() routine works great, far better than array_rand(). Just one small change I'd
make, as mt_rand(0, 0) doesn't work:
$c = count($foo);
for ($i=1; $i<$c; $i++) {
$d = mt_rand(0, $i);
$tmp = $foo[$i];
$foo[$i] = $foo[$d];
$foo[$d] = $tmp;
}
http://php.net/manual/en/function.array-rand.php