/**
* 取得随机数
*
* @param int $length 生成随机数的长度
* @param int $numeric 是否只产生数字随机数 1是0否
* @return string
*/
function random($length, $numeric = 0) {
$seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
$seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
$hash = '';
$max = strlen($seed) - 1;
for ($i = 0; $i < $length; $i++) {
$hash .= $seed{mt_rand(0, $max)};
}
return $hash;
}
php生成随机数
最新推荐文章于 2023-04-30 16:35:11 发布