Php generates a 16-bit random number with only a number and a php16 random number.
Php generates 16-bit random numbers only
Share a php code to generate a 16-bit random number. php can generate a random number in two ways.
Method 1,
<?php$a = mt_rand(10000000,99999999);$b = mt_rand(10000000,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"
A complete string of php code + html php randomly generates 10 digits, and will never be repeated, output in a single line text box
<? Php
$ Result = random (10); // generates a random number of 10 digits.
// $ Result = random (10, '123456789abcdefghijklmnpqrstuvwxyzabcdefghijklmnpqrstuvwxy'); // generate a 10-digit mixed string
Echo "<input type = 'text' size = '20' value = '{$ result}'> ";
/**
* Generate random strings
*
* @ Param int $ length output length
* @ Param string $ chars (Optional). The default value is 0123456789.
* @ Return string
*/
Function random ($ length, $ chars = '20140901 '){
$ Hash = '';
$ Max = strlen ($ chars)-1;
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Hash. = $ chars [mt_rand (0, $ max)];
}
Return $ hash;
}
?>
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 );