<?php
/**
* 获取指定长度字符串
* @author YangYunHao
* @date 2021-03-04 18:33:11
* @param int $length:字符串的长度
* @param bool $numeric:是否是纯数字
* @return string
*/
function random($length, $numeric = false)
{
// $_SERVER['DOCUMENT_ROOT'] 可以换成uuid
$seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
$seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
if ($numeric) {
$hash = '';
} else {
$hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
$length--;
}
$max = strlen($seed) - 1;
for ($i = 0; $i < $length; $i++) {
$hash .= $seed{
mt_rand(0, $max)};
}
return $hash;
}