一个php生成16位随机数的代码(两种方法),16位随机数
分享一个php生成16位随机数的代码,php生成随机数的二种方法。
方法1
复制代码 代码如下:
$a = mt_rand(10000000,99999999);
$b = mt_rand(10000000,99999999);
echo $a.$b;
方法2:
<?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"
有点投机取巧的意味
纯数字的四位随机数
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);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment
