php随机数生成打乱代码

#   php随机数生成打乱代码



<meta http-equiv="content-type" content="text/html;charset=utf-8">
<?php
$numbers = range (1,999);
//shuffle 将数组顺序随即打乱
shuffle ($numbers);
//array_slice 取该数组中的某一段
$num=999;
$result = array_slice($numbers,0,$num);

if($result === array_unique($result)){
    echo 'OK!'.$num.'个随机数生成';//数据没有重复,可以使用
    

$str = implode("\r\n", $result );
   echo "<pre>";
   print_r($str);
   
}else{
    echo 'Fuck,Repeat!';//有重复数据,数据不能使用!
}

unset($result);
exit();


?>


# xiaoxiao [ 2017-08-26 ]

# Address in this article

# http://www.s7smile.com/php/42

# s7smile.com