php生成随机数mt_rand和rand

/**
     * 登录成功后用手机号时间戳随机数
     * 生成token
     */
    public static function token($tel)
    {
        return md5(mt_rand().$tel.time());
    }

    /**
     * 随机字符串昵称
     */
    public static function rand_char(){
        $l = 6;
        $c = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        for ($s = '', $cl = strlen($c)-1, $i = 0; $i < $l; $s .= $c[mt_rand(0, $cl)], ++$i);
        return $s;
    }

PHP 的 rand() 函数默认使用 libc 随机数发生器。mt_rand() 函数是非正式用来替换它的。该函数用了 Mersenne Twister 中已知的特性作为随机数发生器,mt_rand() 可以产生随机数值的平均速度比 libc 提供的 rand() 快四倍(记得mt_rand()比rand()快4倍就够了)。 

原文地址:https://www.cnblogs.com/hanshuai0921/p/7062265.html