A php code to generate a 16-bit random number (two methods), 16-bit random number
Share a php code to generate a 16-bit random number. php can generate a random number in two ways.
Method 1
Copy codeThe Code is as follows:
<? Php
$ A = mt_rand (0000000,99999999 );
$ B = mt_rand (0000000,99999999 );
Echo $ a. $ B;
Method 2:
<? Php $ a = range (0, 9); for ($ I = 0; $ I <16; $ I ++) {$ B [] = array_rand ($ );} // www. yuju100.comvar _ dump (join ("", $ B); // result string (16) "0179571910024734"
How does php generate a 16-bit random number? Only numbers
A little opportunistic
<? Php $ a = mt_rand (, 99999999); $ B = mt_rand (, 99999999); echo $ a. $ B; there is also a way
<? Php $ a = range (0, 9); for ($ I = 0; $ I <16; $ I ++) {$ B [] = array_rand ($ );} var_dump (join ("", $ B); // The result is string (16) "0179571910024734"
A PHP code that generates four random numbers
A random number of four digits.
Rand)
A four-character random string that combines numbers and characters:
Function GetRandStr ($ len)
{
$ Chars = array (
"A", "B", "c", "d", "e", "f", "g", "h", "I", "j ", "k ",
"L", "m", "n", "o", "p", "q", "r", "s", "t", "u ", "v ",
"W", "x", "y", "z", "A", "B", "C", "D", "E", "F ", "G ",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q ", "R ",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1 ", "2 ",
"3", "4", "5", "6", "7", "8", "9"
);
$ CharsLen = count ($ chars)-1;
Shuffle ($ chars );
$ Output = "";
For ($ I = 0; $ I <$ len; $ I ++)
{
$ Output. = $ chars [mt_rand (0, $ charsLen)];
}
Return $ output;
}
Echo GetRandStr (4 );