PHP obtains four-bit letters and numbers in random number implementations, four-bit random numbers
So we know that a simple four-bit digital verification in PHP can be used with Rand (1000,9999), but how do we write a function if we want to get a random four-digit number of letters and numbers? The following Hu Peng Blog in the PHP data column gives a complete example.
<?phpfunction Getfourstr ($len) { $chars _array = Array ( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "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", ); $charsLen = count ($chars _array)-1; $outputstr = ""; for ($i =0; $i < $len; $i + +) { $outputstr. = $chars _array[mt_rand (0, $charsLen)]; } return $outputstr; } Echo getfourstr (4);? >
Part of the function parsing: mt_rand function Description: Mt_rand () returns a random integer.
If no optional parameter min and Max,mt_rand () are provided, the pseudo-random number between 0 and Rand_max is returned. For example, want a random number between 0 and 46 (including 0 and 46), with Mt_rand (0, 46).
http://www.bkjia.com/PHPjc/940489.html www.bkjia.com true http://www.bkjia.com/PHPjc/940489.html techarticle PHP get four-bit letters and numbers of random number implementation method, four-bit random number then we know that in PHP simple four-digit pure digital authentication can be used with Rand (1000,9999), but as ...