note 50414 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:42:33 +0000 |
| Subject: | note 50414 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134410@lists.php.net to get a copy of this message | ||
Note Submitter: ferconstantino at hotmail dot com
----
RANDOM ARRAY (all different numbers)
This is a new version of a function published in this forum:
function GetRandomArray($min,$max,$num) {
#data check
$range = 1 + $max - $min;
if ($num > $range) return false;
if ($num < 1) return false;
#data prep
$result = array();
$count = 0;
$currentnum = 0;
#loop me baby ;-)
while(count($result) < $num) {
$currentnum = rand($min,$max);
if (!in_array($currentnum,$result)){
$result[$count] = $currentnum;
$count++;
}
}
return $result;
}