note 106623 added to function.rand
| From: | jimmyL at osu1 dot php dot net | Date: | Wed, 23 Nov 2011 02:28:46 +0000 |
| Subject: | note 106623 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184628@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.195.64.60
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/106623
Del: integrated -- https://master.php.net/note/delete/106623/integrated
Del: useless -- https://master.php.net/note/delete/106623/useless
Del: bad code -- https://master.php.net/note/delete/106623/bad+code
Del: spam -- https://master.php.net/note/delete/106623/spam
Del: non-english -- https://master.php.net/note/delete/106623/non-english
Del: in docs -- https://master.php.net/note/delete/106623/in+docs
Del: other reasons-- https://master.php.net/note/delete/106623
Reject -- https://master.php.net/note/reject/106623
Search -- https://master.php.net/manage/user-notes.php