Home >Backend Development >PHP Tutorial >php?生成随机数

php?生成随机数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:25:36948browse

如何生成1~9,a~z,A~Z之间XXX位随机数


回复讨论(解决方案)

/**
 * 生成随机数
 * @param int $length ?度
 * @return string
 */
function randomkey($length) {
    $hash = '';
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
    $max = strlen($chars) - 1;
    for ($i = 0; $i         $hash .= $chars[mt_rand(0, $max)];
    }
    return $hash;
}

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