美文网首页
php使用md5生成随机字符串

php使用md5生成随机字符串

作者: 信仰与初衷 | 来源:发表于2018-09-25 23:27 被阅读0次

有时候我们常需要生成一些固定长度的随机字符串,比如uuid,随机字符串等

生成36位uuid

function uuid($prefix = '')  {    
    $chars = md5(uniqid(mt_rand(), true));    
    $uuid  = substr($chars,0,8) . '-';    
    $uuid .= substr($chars,8,4) . '-';    
    $uuid .= substr($chars,12,4) . '-';   
    $uuid .= substr($chars,16,4) . '-';    
    $uuid .= substr($chars,20,12);    
    return $prefix . $uuid;  
}  

echo uuid();

生成随机32位字符串

function str_rand($length = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
    if(!is_int($length) || $length < 0) {
        return false;
    }

    $string = '';
    for($i = $length; $i > 0; $i--) {
        $string .= $char[mt_rand(0, strlen($char) - 1)];
    }

    return $string;
}

echo str_rand(),

利用微秒时间戳生成32位唯一字符串

$uniqid = md5(uniqid(microtime(true),true));
echo $uniqid;

相关文章

  • JavaUtils

    生成随机字符串 Md5加密

  • php使用md5生成随机字符串

    有时候我们常需要生成一些固定长度的随机字符串,比如uuid,随机字符串等 生成36位uuid 生成随机32位字符串...

  • Lottery

    解题思路 原理 其中 win_numbers 是随机生成的数字字符串。使用 PHP 弱类型松散比较,以"1"为例,...

  • Qt 杂录

    UUID MD5 随机数 Qt5.10后推荐使用 QRandomGenerator 生成随机数,而不再推荐qran...

  • php 生成 java 的md5

    php的md5 默认是32位的长度与java的默认生成的md5不同 使用方法

  • 用户密码生产规则

    随机数生成 MD5 BASE64 密码生成

  • MySQL生成随机字符串的三种方法

    一、使用rand函数 说明 rand():随机函数,会生成0~1之间的随机数 md5(input):散列函数,根据...

  • Golang 生成随机数字、随机字符串

    生成随机数字 生成随机字符串

  • python随机值

    import stringimport randomimport hashlib 随机数字 随机字符串 md5值

  • iOS 代码混淆

    使用STCObfuscator框架可以生成Md5加密的字符串,在debug环境下运行生成混淆宏,在release打...

网友评论

      本文标题:php使用md5生成随机字符串

      本文链接:https://www.haomeiwen.com/subject/xxyroftx.html