note 73707 deleted from function.rand by felipe

From: Date: Sun, 09 Dec 2007 15:39:57 +0000
Subject: note 73707 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133025@lists.php.net to get a copy of this message
Note Submitter: kurtubba at gmail dot com ---- Trying to pick up random keys from an array but don't want any duplicates? try this //returns an array of random keys between 2 numbers function &UniqueRands($min, $max, $keys){ static $returnme = array(); while(in_array($x = rand($min,$max),$returnme)); $returnme[] = $x; if($keys < count($returnme)-1 && $keys < ($max-$min)) UniqueRands($min, $max, $keys); return $returnme; } //usage $rands = & UniqueRands(0, 15, 5);

« previous php.notes (#133025) next »