A method of generating PHP random numbers from digital letters

Source: Internet
Author: User
In the previous we have introduced the PHP random number generation method, but did not specifically describe the generated PHP random number is what, then we will introduce the PHP random generation of digital letter combination method, an example of PHP generated random numbers and random letters related techniques and usage, very practical value, Need friends can refer to the next!

A method of generating PHP random numbers from digital letters

function getrandomstring ($len, $chars =null) {    if (Is_null ($chars)) {        $chars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";    }      Mt_srand (10000000* (double) microtime ());    for ($i = 0, $str = ", $LC = strlen ($chars)-1; $i < $len; $i + +) {        $str. = $chars [Mt_rand (0, $LC)];      }    return $STR;}

For example randomly generated 2-bit letters and number combinations
Just call the function and pass parameter 2.

Echo getrandomstring (2);

If you just generate lowercase letters you can use a similar method

Echo Chr (Mt_rand (65, 90);

Capital

Echo Chr (Mt_rand (97, 122));

Summarize:

See here believe a lot of small partners on the generation of PHP random number and further understanding, can have alphanumeric composition, as well as the letter of the case, this article can do a good job, hope to your work has some help!

Related recommendations:

Five ways to generate PHP random numbers without repetition


A method for generating random numbers in PHP


PHP random number red envelope random generation algorithm PHP version

Related Article

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.