There are 25 pieces to vote, one to vote for 16, and one to vote only once per piece. In front of a programmer stabbed blunder, forgot to put the vote in the library, there are 200 user-generated voting sequence is empty. So how would you fill this blunder?
Certainly reflect the situation to the superiors. But what we're talking about here is the technology that needs to generate 16 non-repeating random numbers between 1-25 to fill. How do you design the function specifically? A certain number of distinct random numbers can be generated by storing random numbers in an array and then removing duplicate values in the array. Eternal Profit Meeting Casino
The procedure is as follows:
<?php/** array Unique_rand (int $min, int $max, int $num) * Generates a certain number of distinct random numbers * $min and $max: Specify the range of random numbers * $num: Specify the number of builds */functio N Unique_rand ($min, $max, $num) { $count = 0; $return = Array (); while ($count < $num) { $return [] = Mt_rand ($min, $max); $return = Array_flip (Array_flip ($return)); $count = count ($return); } Shuffle ($return); return $return;} $arr = Unique_rand (1, +), sort ($arr), $result = ", for ($i =0; $i < count ($arr); $i + +) {$result. = $arr [$i]. ', ';} $result = substr ($result, 0,-1); Echo $result;? >
The program runs as follows:
2,3,4,6,7,8,9,10,11,12,13,16,20,21,22,24
PHP CodeBase: Generate n non-repeating random numbers