PHP get four-bit letters and numbers of random number implementation method, four-bit random number _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.