PHP function: Generate n non-repeating random number, PHP random number _php Tutorial

Source: Internet
Author: User

PHP function: Generate n non-repeating random number, PHP random number


PHP function: Generate n non-repeating random numbers


Idea: A certain number of distinct random numbers can be generated by depositing the generated random number into an array and then removing the duplicate values in the array.

Program:

 

Additional notes:

1. Generate random numbers using the Mt_rand () function, which is 4 times times faster than the rand () function;

2, the elimination of duplicate values of the array using the "rollover method", is to use Array_flip () the array of key and value exchange two times. Much faster than using Array_unique ().


How does matlab produce random numbers that are not duplicated?

Rand (1,8) *100
Ans =
Columns 1 through 7
81.4724 90.5792 12.6987 91.3376 63.2359 9.7540 27.8498
Column 8
54.6882

Using Excel to generate n random numbers, how to use an if function to make it non-repeating

Select a1:a1000, and in the formula bar, enter
=rand ()
Press "CTRL + ENTER"
Select b1:b1000, and in the formula bar, enter
=rank (a1,a$1:a$1000)
Press "CTRL + ENTER"

http://www.bkjia.com/PHPjc/827776.html www.bkjia.com true http://www.bkjia.com/PHPjc/827776.html techarticle PHP Function: Generate n non-repeating random number, PHP random number PHP function: Generate n non-repeating random number idea: the generated random number into an array, and then remove the duplicate values in the array ...

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