A php code to generate a 16-bit random number (two methods), 16-bit random number
A php code that generates a 16-bit random number. php can generate a random number in two ways.
Method 1
<? 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.com
Var_dump (join ("", $ B ));
// Result: string (16) "0179571910024734"
Reference link:
- Several examples of generating non-repeated random numbers using php
- How does php generate a 6-digit random number? example of a php Random Number
- Three methods for generating random numbers using php
- Example of a php random number. The php background color is displayed randomly.
- Php random number generation function example
- Sample Code for php Random Number Generation
- Php generates random numbers. php generates fixed-digit random numbers.
- Example of generating a random number or string using php
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 );