php生成指定长度的随机数字_PHP教程
时间:2021-07-01 10:21:17
帮助过:14人阅读
01
/**
02
* 生成指定长度的随机数字
03
* @author yangyingjie
04
* @param $number
05
* @return string
06
*/
07
function createRandNumberBySize($number)
08
{
09
$number = (int)$number;
10
if ($number === 0) {
11
return '';
12
} else {
13
$rankNumberString = "";
14
for ($i = 0; $i < $number + 1; $i++) {
15
if ($i !== 0 && $i % 2 === 0) {
16
$rankNumberString .= mt_rand(11, 99);
17
}
18
}
19
20
if ($number % 2 === 0) {
21
return $rankNumberString;
22
} else {
23
return $rankNumberString . mt_rand(1, 9);
24
}
25
26
}
27
}
作者:杨哥哥
http://www.bkjia.com/PHPjc/478104.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478104.htmlTechArticle01 /** 02 * 生成指定长度的随机数字 03 * a href=http://my.oschina.net/arthor target=_blank rel=nofollow@author/a yangyingjie 04 * @param $number 05 * a href=http://my.osch...