DEMO:

  unique_rand(最小值,最大值,输出数量)

 

//生成指定区间不重复随机正整数
    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;
    }

https://www.jb51.net/article/157965.htm