<?
substr(md5(rand(0,100000)),0,15)
?>这样么?不行啊。
能写个完整的么?

解决方案 »

  1.   

    <?
    echo substr(md5(rand(0,100000)),0,15);
    ?>
      

  2.   

    rand(0,100000)
    会重复吧.--
    是啊,我也觉得,md5算法对固定的数字每次结果都是一样的吧?那即使用md5(rand(0,10000))也只有100001种结果吧?
      

  3.   

    给你一个。你比较下:
    <?php
    function random_char($string)
    {
    $length = strlen($string);
    $position = mt_rand(0, $length - 1);
    return($string[$position]);
    }
    function random_string ($charset_string, $length)
    {
    $return_string = ""; // the empty string
    for ($x = 0; $x < $length; $x++)
    $return_string .= random_char($charset_string);
    return($return_string);
    }
    mt_srand((double)microtime() * 1000000);
    $charset = "abcdefghijklmnopqrstuvwxyz0123456789";//use random_string()
    $mystr = random_string($charset,15);
    echo $mystr . "<br>";
    //use md5()
    echo substr(md5(mt_rand(0,100000)),0,15);
    ?>
      

  4.   

    怕重复的话你可以剩以 time() 啊
      

  5.   

    注: 在 PHP 4.2.0 中,无需用函数 srand() 或 mt_srand()来搜寻随机数生成器,它将被自动完成。 
    好像是这样,不过学习方法!!
      

  6.   

    /**
    *
    *   作者:偶然
    *   功能:生成四位随机数
    *   时间:2004.2.1
    *
    */
    function rand_num()
    {
    global $authnum;
    srand((double)microtime()*1000000);
    while(($authnum=rand()%10000)<1000);
    Return $authnum;
    }我一直在用偶然写的这个东西
    //如果你1秒中内插入了6000条记录,恭喜你报错1次
    $title_id = md5(rand_num()+time());
      

  7.   

    srand((double)microtime()*1000000);
    substr(md5(uniqid(rand())),0,15);
    呵呵,不错,就是包含字符种类太少。
      

  8.   

    function randString($len=4){  
        $chars="23456789ABCDEFGHJKLMNPRSTWXY";
        $string=""; 
        for($i=0;$i<$len;$i++){ 
            srand((double)microtime()*1000000); 
            $rand=rand(0,strlen($chars)-1); 
            $string.=substr($chars,$rand,1); 
        } 
        return strtoupper($string);  
    }
      

  9.   

    我也来凑个热闹function foo() {
      $s = '0123456789abcdefghijklmnopqrstuvwxyz';
      preg_match_all('/./', $s, $r);
      shuffle($r[0]);
      return join('', array_slice($r[0], 15));
    }
      

  10.   

    /**
     * 通过时间和随机数得到唯一的14位标识ID
     *
     * 取Unix时间戳,共10位  +  随机数4位  =  14位
     *
     * @author liuhb
     * @since 1.1
     * @copyright Bizsms Copyright 2005
     * @since 2005年5月8日
     * @access public
     * @param NULL
     * @return string
     */
    function getSeqID()
    {
    // 取Unix时间戳,共10位
    list($usec, $sec) = explode(" ", microtime()); 
    $strsec = sprintf("%s", $sec); for ($i=0; $i<4; $i++)
    {
    $strsec = $strsec.rand(0, 9);
    } return $strsec;
    }
      

  11.   

    /**
     * 随机产生Handle序列
     *
     * @param
     * @return handle
     */
    function createID($len=14)
    {
    $handle = "";
    $array  = array(1,2,3,4,5,6,7,8,9,0,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);
    //$array1 = 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); while (strlen($handle) < $len)
    {
    $i = rand(0, 61);
    $handle .= $array[$i];
    } return $handle;
    }
      

  12.   

    要不可以用pear, pear::text_password,嘿嘿