PHP Source Code Analysis DZX1.5 random number function _php Tutorial

Source: Internet
Author: User
Tags php source code

PHP Source Code Analysis DZX1.5 random number function


The example of PHP source code Analysis of the DZX1.5 random number function. Share to everyone for your reference. Specific as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

/**

* @param int $length: Random number length

* @param int $numeric: 0 or not 0, where 0 means that the random number consists of a full number, not 0 means that the random number consists of a full letter

* @return string: Returns the generated random number

*/

function random ($length, $numeric = 0) {

$seed = Base_convert (MD5 (microtime () $_server[' Document_root '), $numeric? 10:35);

$seed = $numeric? (Str_replace (' 0 ', ', $seed). ' 012340567890 '): ($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 results of the operation are as follows:

228283270677112

Sjqffsu76994qfs

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1018378.html www.bkjia.com true http://www.bkjia.com/PHPjc/1018378.html techarticle PHP Source Code Analysis of the random usage of the DZX1.5 stochastic function This paper describes the PHP source code Analysis of the DZX1.5 random number function. Share to everyone for your reference. Specific as follows:? 1 ...

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