Home > Backend Development > PHP Tutorial > A PHP code to generate 16-digit random numbers (two methods), 16-digit random numbers_PHP tutorial

A PHP code to generate 16-digit random numbers (two methods), 16-digit random numbers_PHP tutorial

WBOY
Release: 2016-07-13 10:18:55
Original
1286 people have browsed it

A php code to generate a 16-digit random number (two methods), 16-digit random number

A php code to generate a 16-digit random number, php to generate a random number Two ways to count.

Method 1
$a = mt_rand(10000000,99999999);
$b = mt_rand(10000000,99999999);
echo $a.$b;

Method 2:
$a = range(0,9);
for($i=0;$i<16;$i++){
$b [] = array_rand($a);
} // www.yuju100.com
var_dump(join("",$b));
//result string(16) "0179571910024734"

Reference link:

How to generate 16-digit random number in php? Only numbers

A bit opportunistic
< ?php$a = range(0,9);for($i=0;$i<16;$i++){$b[] = array_rand($a);}var_dump(join("",$b) );//result string(16) "0179571910024734"

A PHP code that generates four-digit random numbers

Pure numeric four-digit random number
rand(1000,9999)
Four-digit random string mixed with 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);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/879486.htmlTechArticleA php code to generate a 16-digit random number (two methods), 16-digit random number, a php generates 16 Code for random numbers, two ways for PHP to generate random numbers. Method 1 ?php $a = mt_rand(100000...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template