如何產生綜合亂數

請問要如何產生數字+英文的亂數

是用RAND嗎~~~~

s4adg45456asg56

類似這樣的

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    1.用現有函數

    <?

    echo uniqid(1);

    ?>

    http://tw.php.net/manual/en/function.uniqid.php

    2.用亂數產生更亂的

    <?php

    function gen_passw($len = 8)

    {

    $ranges = array

    (

    1 => array(97, 122), // a-z (lowercase)

    2 => array(65, 90), // A-Z (uppercase)

    3 => array(48, 57) // 0-9 (numeral)

    //假如你連符號也要進去 可以把符號的ASCII

    //CODE範圍找出來

    );

    $passw = "";

    for ($i=0; $i<$len; $i++)

    {

    $r = mt_rand(1,count($ranges));

    $passw .= chr(mt_rand($ranges[$r][0], $ranges[$r][1]));

    }

    return $passw;

    }

    //怎麼用? 呼叫gen_passw函數 裡面指定你要的字串長度

    echo gen_passw(6);

    ?>

    http://tw.php.net/manual/en/function.mt-rand.php

Still have questions? Get your answers by asking now.