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

php?生成随机数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:25:36
Original
972 people have browsed it

如何生成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;
}

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template