Php source code analysis-DZX1.5 random number function random usage

Source: Internet
Author: User
This article describes how to use the DZX1.5 random number function random in php source code analysis. The example shows how to use the random function in DZX1.5 to generate random strings, for more information about how to use the DZX1.5 random number function random in php source code analysis, see the following example. Share it with you for your reference. The details are as follows:

<? Php/*** @ param int $ length: Random number length * @ param int $ numeric: 0 or not 0, where 0 indicates that the random number is composed of all numbers, A non-0 random number is composed of all letters * @ return string: returns the generated random number */function random ($ length, $ numeric = 0) {$ seed = base_convert (md5 (microtime (). $ _ SERVER ['document _ root']), 16, $ numeric? 10: 35); $ seed = $ numeric? (Str_replace ('0', '', $ seed ). '20140901'): ($ seed. 'zz '. strtoupper ($ seed); $ hash = ''; $ max = strlen ($ seed)-1; for ($ I = 0; $ I <$ length; $ I ++) {$ hash. = $ seed {mt_rand (0, $ max) };}return $ hash;} echo random ('15', 1); echo'
'; Echo random ('15');/* End of php */

The running result is as follows:

228283270677112
SjqffsU76994qfS

I hope this article will help you with php programming.

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.