<?php |
/* |
* array unique_rand( int $min, int $max, int $num ) |
* 生成一定数量的不重复随机数 |
* $min 和 $max: 指定随机数的范围 |
* $num: 指定生成数量 |
*/ |
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 ; |
?> |