zoukankan      html  css  js  c++  java
  • php案列4

                                                                

    一个最简单的利用php生成随机数或者随机字符串的函数.$chars变量中的字符自己修改就能达到数字或者字符串的目的

     

     

    $len表示长度,代码如下:

    复制代码 代码如下:

    /** * 产生随机字符串 * * 产生一个指定长度的随机字符串,并返回给用户 * * @access public * @param int $len 产生字符串的位数 * @return string */ function randstr($len=6) { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789-@#~'; // characters to build the password from mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return $password; }

  • 相关阅读:
    UESTC
    Education Round 8 A
    Gym
    Gym
    hdoj 1159 Common Subsequence
    UVA
    UESTC
    51Nod 1068 Bash游戏 V3 (这规律不好找)
    51Nod 1066 Bash游戏
    51Nod 1002 数塔取数问题
  • 原文地址:https://www.cnblogs.com/xa4312cs/p/6132430.html
Copyright © 2011-2022 走看看