PHP n unique random number generation code example

怪我咯
Release: 2023-03-13 14:16:01
Original
1165 people have browsed it

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); 
?>
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!