PHP: method for generating random numbers without duplicates. php method for repeating random numbers _ PHP Tutorial

Source: Internet
Author: User
Tags shuffle
PHP: the method for generating random numbers without duplicates. the php method for repeating random numbers. PHP: the method for generating random numbers that are not repeated. the method for generating random numbers in php is Source: www.ido321.com1217.html. for Web applications, WAP or mobile applications, random numbers are applicable to PHP: method for generating non-repeated random numbers, php method for repeating random numbers

Source: http://www.ido321.com/1217.html

Random numbers are useful for Web applications, WAP or mobile applications. In recent small projects, I often need to deal with random numbers or random arrays. Therefore, I would like to summarize several common methods for generating non-repeated random numbers in PHP (ps: methods 1, 4, and 5 are commonly used, and the rest are from network arrangement)

Method 1:

 

Method 2:

 

Method 3:

 

Five distinct values can be randomly generated between 1 and 20.

Method 4:

 

Method 5:

 

This may be simpler (ps: If the step is specified in the range, you must note whether the second parameter of array_rand exceeds the length of $ tmp ).

PHP provides a rich array function, and generates random numbers most of the time from the array perspective. if you have other methods available, please refer to the article for continuous updates.

Next Article: PHP: method for generating random numbers without duplicates

Random Source: http://www.ido321.com/1217.html whether it is Web applications, or WAP or mobile applications, random numbers are useful...

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.