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:
<? Php/** array unique_rand (int $ min, int $ max, int $ num) * generate a certain number of random numbers not repeated * $ min and $ max: specify the random number range * $ num: specify the number of generated records */function unique_rand ($ min, $ max, $ num) {$ count = 0; $ return_arr = array (); while ($ count <$ num) {$ return_arr [] = mt_rand ($ min, $ max); $ return_arr = array_flip ($ return_arr )); $ count = count ($ return_arr);} shuffle ($ return_arr); return $ return_arr ;}
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
Use excel to generate N random numbers. How can I use the if function so that A1: A1000 is not selected repeatedly? In the editing column, enter
= RAND ()
Press CTRL + press Enter]
Select B1: B1000, and enter
= RANK (A1, a $1: A $1000)
Press CTRL + press Enter]