Home > php教程 > php手册 > php生成指定长度的随机数字

php生成指定长度的随机数字

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:50:52
Original
1362 people have browsed it

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 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
}

作者:杨哥哥

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template