- /*
- * array unique_rand( int $min, int $max, int $num )
- * Generate a certain number of unique random numbers
- * $min and $max: specify the random number Range
- * $num: Specify the generated number
- */
- function unique_rand($min, $max, $num) {
- $count = 0;
- $return = array();
- while ($count < $num) {
- $return[] = mt_rand($min, $max);
- $return = array_flip(array_flip($return));
- $count = count($return);
- }
- shuffle($return);
- return $return;
- }
-
- $arr = unique_rand(1, 25, 16);
- sort($arr);
-
- $result = '';
- for($i=0; $i < count($arr );$i++)
- {
- $result .= $arr[$i].',';
- }
- $result = substr($result, 0, -1);
- echo $result;
- ?>
Copy code
|