Copy the code The code is as follows:
//range is to list 1 to 100 into an array
$numbers = range (1,100);
//shuffle will disrupt the order of the array
shuffle ($numbers);
//array_slice Get a certain segment in the array
$no=6;
$result = array_slice($numbers,0,$no);
for ($i=0;$i<$ no;$i++){
echo $result[$i]."
";
}
print_r($result);
?>
Copy code The code is as follows:
//range is to list 1 to 42 into an array
$numbers = range (1,42);
//shuffle will disrupt the order of the array
shuffle ($numbers);
//array_slice takes the array A certain section
$result = array_slice($numbers,0,3);
print_r($result);
Copy code The code is as follows:
$numbers = range (1,20);
srand ((float)microtime()*1000000);
shuffle ($numbers);
while (list (, $number) = each ($numbers)) {
echo "$number " ;
}
?>
Copy the code The code is as follows:
function NoRand($begin=0,$end=20,$limit=5){
$rand_array=range($begin,$end);
shuffle($rand_array);//Call the ready-made array random arrangement function
return array_slice($rand_array,0,$limit);//Intercept the first $limit
}
print_r(NoRand());
?>
Copy the code The code is as follows:
$tmp=array();
while(count($tmp)<5){
$tmp[]=mt_rand(1,20);
$tmp=array_unique($tmp) ;
}
print join(',',$tmp);
?>
The above introduces the vb random number PHP n non-repeating random number generation code, including the vb random number content. I hope it will be helpful to friends who are interested in PHP tutorials.