note 106623 deleted from function.rand by danbrown
| From: | danbrown@php.net | Date: | Tue, 29 Nov 2011 15:53:53 +0000 |
| Subject: | note 106623 deleted from function.rand by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184798@lists.php.net to get a copy of this message | ||
Note Submitter: jimmy L
----
Here is another function that will return an array of unique random numbers. It may be more
efficient than the one below when dealing with a large range.
<?php
function generate_random_numbers($min,$max, $total){
$x = 0; $out = array();
while($x < $total){
$num = rand($min, $max);
if($x){
while(in_array($num, $out)){
$num = rand($min, $max);
}
}
$out[$x] = $num;
$x++;
}
return $out;
}
?>