note 43517 deleted from function.rand by nlopess

From: Date: Thu, 24 Jun 2004 08:55:19 +0000
Subject: note 43517 deleted from function.rand by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71568@lists.php.net to get a copy of this message
Note Submitter: mike at ^nospam$wecantlose.com ---- This function returns an array of unique random numbers. <? // Multiple Unique Random Numbers // // Usage: mrand ( quanity of uniques, lowest value, highest value ) // function mrand($l,$h,$total){ $n = array(); do{ $num = rand($l,$h); if(array_search($num,$n) === false)$n[] = $num; }while(count($n)<$total); return $n; } // 20 unique numbers between 100 and 120 $numbers = mrand(100,120,20); // Sort the array sort($numbers); // Display the array foreach($numbers as $number) { echo $number.' '; } ?>

« previous php.notes (#71568) next »