Mt_rand () returns a random integer using the Mersenne twister algorithm.
Syntax: Mt_rand (Min,max)
Note: If you do not provide optional parameters min and Max,mt_rand () return the pseudo-random number between 0 and Rand_max, such as a random number between 5 and 15 (including 5 and 15), use Mt_rand (5,15).
In the previous version of 3.0.7, Max meant a range, and to get the same number of random numbers in these versions as the previous example is 5 to 15, the short example is Mt_rand (5, 11).
The PHP instance code is as follows:
$rand = Mt_rand (0,1);
if ($rand ==0)
{
$array = Array (41,20,26,29,30);
}
ElseIf ($rand ==1)
{
$array = Array (38,42,37,400,444);
}//Open source software: phpfensi.com
foreach ($array as $v => $vv)
{
echo "$VVN";
}
Using time and Mt_rand functions to get random names
<?php
/**
* Created by Phpstorm.
* User:administrator
* DATE:2016/9/19 0019
* time:19:47
*/
function Rdname () {
$t = getdate ();
$year = $t [' Year '];
$month = $t [' Mon ']<10? "0" $t [' mon ']: $t [' mon '];
$day = $t [' Mday ']>9] $t [' Mday ']: "0" $t [' mday '];
$hour = $t [' Hours ']>9] $t [' Hours ']: "0" $t [' hours '];
$min = $t [' minutes ']>9] $t [' minutes ']: "0" $t [' minutes '];
$sec = $t [' seconds ']>9] $t [' seconds ']: "0" $t [' seconds '];
$randnum =mt_rand (1000,9999);//Get a random 4 digits
$randname = $year. $month. $day. $hour $min. $sec.//The date of the year and the random number splicing together
return $randname//returns a new name
}
$newname =rdname ()//Assign the returned name to $newname
echo $newname;?>