note 29129 deleted from function.shuffle by aidan
| From: | aidan@php.net | Date: | Thu, 26 Aug 2004 22:34:03 +0000 |
| Subject: | note 29129 deleted from function.shuffle by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75369@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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.