note 50414 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.