Re: similar to shuffle()
| From: | Chana Black | Date: | Thu, 01 Feb 2001 19:14:31 +0000 |
| Subject: | Re: similar to shuffle() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37688@lists.php.net to get a copy of this message | ||
I had the same problem... I wrote a function that does this:
function scramble(&$array)
{
// scrambles the elements of a one dimentional array
// written by cblack (cblack@teamgenesis.com)
// in php3 >= 3.0.8, there's a function called shuffle that does this
for ($i=0;$i<sizeof($array);$i++)
{
// seed random number generator
srand((double) microtime() * 1000000);
// store whatever is in $array[$i] in a temp var
$temp = $array[$i];
// generate a random number to swap with
$newvalue = rand(0, sizeof($array));
// swap values
$array[$i] = $array[$newvalue];
$array[$newvalue] = $temp;
}
return 1;} Feel free to modify... CB At 02:06 PM 2/1/01 -0500, Jason Jacobs wrote:
Does anyone know of a function in version 3.0.7 that does the same thing to shuffle(), which was implemented in 3.0.8? I'm trying to run a banner script I found, and I guess we were 1 one-hundredth of a version off for this thing... Or, how painless is it to upgrade to the latest version? I'm assuming that PHP is backwards compatible... Thanks. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net