note 50015 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:42:23 +0000 |
| Subject: | note 50015 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134407@lists.php.net to get a copy of this message | ||
Note Submitter: phpdeveloper AT o2 DOT pl
----
This is most simple random array generator, hope zo ;-)
Moreover it uses some PHP array features :-), and does not search through array haystack, just
checks for data if its set :P.
<?php
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();
$a = rand($min,$max);
$result[$a] = $a;
#loop me baby ;-)
while(count($result) < $num) {
do {$a = rand($min,$max); } while(isset($result[$a]));
$result[$a] = $a;
}
return $result;
}
var_dump(GetRandomArray(3,10,5));
?>
nice coding 4 U all :-)
[k3oGH]