PHP fixed-length string

/ * * 
 * Get fixed length random string 
 * @param $ n- 
 * @return String 
 * @throws Exception 
 * / 
function gf_rand_str ( $ n- ) {
     IF (! Of is_int ( $ n- )) {
         the throw  new new  Exception ( 'argument MUST BE int ' ); 
    } 
    $ Alpha =' ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ' ;
     $ STR =' ' ;
     for ( $ I = 0; $ I < $ n- ; $ I ++ ) {
         $ STR . = $ Alpha[rand(0, 35)];
    }
    return $str;
}

After the first three letters three numbers:

function invite_num($len = 6)
{
    $en_chars = [
        "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"
    ];
    $num_chars = [
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
    ];
    for;
    = ""$ the Output);
    $ num_chars(shuffle=$ num_shufarray disrupt the//);    $ en_chars(shuffle=en_shuf $
     ($i = 0; $i < 3; $i++) {
        $output .= $en_chars[mt_rand(0, $len)];
    }
    $output .= substr(getMicroSecondsTimestamp(), 11, 1);
    $output .= rand(10, 99);
    return $output;
}
function getMicroSecondsTimestamp()
{
    $time = microtime();
    return substr($time, 11, 10) . str_pad(substr($time, 0, 8) * 1000000,
            6, "0", STR_PAD_LEFT);
}

Guess you like

Origin www.cnblogs.com/sgm4231/p/12073121.html