Home >Backend Development >PHP Tutorial >PHP n unique random number generation code example
Whether it is a web application, a WAP or a mobile application, random numbers have their place. This article introduces PHP n non-repeating random number generation code examples
The code is as follows:
<?php //range 是将1到100 列成一个数组 $numbers = range (1,100); //shuffle 将数组顺序随即打乱 shuffle ($numbers); //array_slice 取该数组中的某一段 $no=6; $result = array_slice($numbers,0,$no); for ($i=0;$i<$no;$i++){ echo $result[$i]."<br>"; } print_r($result); ?>
The code is as follows:
//range 是将1到42 列成一个数组 $numbers = range (1,42); //shuffle 将数组顺序随即打乱 shuffle ($numbers); //array_slice 取该数组中的某一段 $result = array_slice($numbers,0,3); print_r($result);
The above is the detailed content of PHP n unique random number generation code example. For more information, please follow other related articles on the PHP Chinese website!