醉菜鸟 2021-11-25 09:00:07

php生成随机数/生成随机字符串的方法

/** 
 * 随机字符串 
 * @param int $length 
 * @return string 
 */
function nonce_str($length = 32){   
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
    $randomString = '';   
    for ($i = 0; $i < $length; $i++)    {  
        $randomString .= $characters[rand(0, strlen($characters) - 1)];  
    }   
    return $randomString;
}
意见反馈