PHP function: Generate N non-repeated random numbers. php random number _ PHP Tutorial

Source: Internet
Author: User
PHP function: Generate N non-repeated random numbers and php random numbers. PHP function: Generate N random numbers without duplicates. php random number PHP function: Generate N random numbers without duplicates. train of thought: store the generated random number into an array, remove duplicate values in the array. PHP function: Generate N non-repeated random numbers and php random numbers.
PHP function: Generate N random numbers that are not repeated

Idea: store the generated random number into an array, and then remove duplicate values in the array to generate a certain number of non-repeated random numbers.

Program:

 

Note:

1. the mt_rand () function is used to generate random numbers. This function is four times faster than the rand () function;

2. when the array repeated values are removed, the "flip method" is used, that is, the array key and value are exchanged twice with array_flip. It is much faster than array_unique.


How does matlab generate random numbers that are not repeated?

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

How to use the if function to generate N random numbers in excel

Select A1: A1000, and enter
= RAND ()
Press CTRL + press Enter]
Select B1: B1000, and enter
= RANK (A1, a $1: A $1000)
Press CTRL + press Enter]

Random number PHP function: Generate N non-repeated random numbers. train of thought: store the generated random number into an array, and then remove repeated values in the array...

Related Article

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.