• 技术文章 >php教程 >PHP源码

    php 生成随机函数

    2016-06-08 17:28:40原创398

    php 生成随机函数

    function genRandomString($len)
    {
    $chars = array(
    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
    "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
    "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
    "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
    "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
    "3", "4", "5", "6", "7", "8", "9"
    );
    $charsLen = count($chars) - 1;
    shuffle($chars);
    $output = "";
    for ($i=0; $i<$len; $i++)
    {
    $output .= $chars[mt_rand(0, $charsLen)];
    }
    return $output;
    }

    还有一种是php 自带的mt_rand 与rand 哦,不过建意最好用mt_rand这个事速度上优与rand

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:quot nbsp rand chars output
    上一篇:ajax 级联动菜单代码 下一篇:Ffmpeg实现视频格式的转换以及截图
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• php给图片加水印四• php简单文件上传代码• uploadify+PHPExcel无刷新导入数据-完善中3• 极简的创建文件夹函数 • PHP一个敏感信息过滤思路
    1/1

    PHP中文网