Use of the mt_rand () random number function in php

Source: Internet
Author: User
This article mainly introduces the usage of the mt_rand () random number function in php, analyzes the common usage of the mt_rand () random number function in detail, and provides an example of random output in combination with array traversal, for more information about how to use the mt_rand () random number function in php, see the following example. Share it with you for your reference. The specific analysis is as follows:

Mt_rand () returns a random integer using the mersenne twister algorithm.

Syntax: mt_rand (min, max)

Note: if the optional parameters min and max, mt_rand () are not provided, a pseudo-random number between 0 and rand_max is returned, for example, a random number between 5 and 15 (including 5 and 15) is required, use mt_rand (5, 15 ).

In versions earlier than 3.0.7, max indicates range. in these versions, a random number of 5 to 15 is obtained, which is the same as that in the previous example. in a short example, mt_rand (5, 11 ).

The PHP instance code is as follows:

The code is as follows:

$ Rand = mt_rand (0, 1 );
If ($ rand = 0)
{
$ Array = array (, 30 );
}
Elseif ($ rand = 1)
{
$ Array = array (37,400,444 );
}
Foreach ($ array as $ v => $ vv)
{
Echo "$ vvn ";
}

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.