note 29129 added to function.shuffle
| From: | php-general at lists dot php dot net | Date: | Tue, 04 Feb 2003 00:49:20 +0000 |
| Subject: | note 29129 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43357@lists.php.net to get a copy of this message | ||
Another alternative to shuffle:
function rand_cmp( $a, $b )
{
$num = (rand( 0, 2 )) - 1;
return round( $num );
}
usort( $somearray, "rand_cmp");
This returned faster and more reliable results for me on a Windows box than shuffle. It also
provides a good foundation to expand into "weighted" randomization as needed. Since it
uses usort, it may still be a problem on Solaris. Feel free to post an update in that regard.
--
http://www.php.net/manual/en/function.shuffle.php
http://master.php.net/manage/user-notes.php?action=edit+29129
http://master.php.net/manage/user-notes.php?action=delete+29129
http://master.php.net/manage/user-notes.php?action=reject+29129