Home >php教程 >php手册 >一个php生成16位随机数的代码(两种方法),16位随机数

一个php生成16位随机数的代码(两种方法),16位随机数

WBOY
WBOYOriginal
2016-06-13 09:25:241626browse

一个php生成16位随机数的代码(两种方法),16位随机数

分享一个php生成16位随机数的代码,php生成随机数的二种方法。

方法1

复制代码 代码如下:


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


方法2:

<&#63;php
$a = range(0,9);
for($i=0;$i<16;$i++){
$b[] = array_rand($a);
} // www.yuju100.com
var_dump(join("",$b));
//结果string(16) "0179571910024734"

php 怎生成16位随机数?只有数字

有点投机取巧的意味
 

一个生成四位随机数的PHP代码

纯数字的四位随机数
rand(1000,9999)
数字和字符混搭的四位随机字符串:

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 {
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
echo GetRandStr(4);
 

Statement:
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