PHP implementation of multiple random numbers within a specified range of methods

Source: Internet
Author: User
Generate random data in PHP we can use Rand,mt_rand can be generated in the specified range of random data, the following for you to introduce the method of the students

Call Mt_rand () This method can generate random numbers, which are the minimum and maximum values of the range, and the function returns a random number between the minimum and maximum values.
To generate a true random number is not an easy task for computing.

There are two methods in PHP that can generate random numbers, a classic function called Rand (), and the other better function is Mt_rand ().

Example 1

The code is as follows

$random =rand (0,1000);

Or

<?php $rand = Mt_rand (1, +);  Echo $rand;? >

Example 2

The code is as follows

Srand (Double) microtime () *1000000); $random =rand (0,1000);

Example 3

The code is as follows

/** * Get multiple random numbers within a certain range */function yang_numberrand ($begin = 0, $end = 5, $limit =) {   $rand _array = Range ($begin, $end);   Shuffle ($rand _array);//Call out-of-the-box array random permutation function   return array_slice ($rand _array, 0, $limit);//Pre-intercept $limit}

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.