Home > Backend Development > PHP Tutorial > php?生成随机数解决方案

php?生成随机数解决方案

WBOY
Release: 2016-06-13 12:25:17
Original
1068 people have browsed it

php?生成随机数
如何生成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:
source:php.cn
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