This is no good nonsense;
The first is to use the Mt_rand () function to generate a specified number of random numbers;
Then use the Array_unique () function to go heavy;
Because go heavy, so get the number is not enough to specify the number of;
So, the core is to use the while loop, until the number of the specified number is obtained;
The basic can be the end here;
For the perfect person, you can also use a sort ();
The purpose is not to be used for sorting; The key is to format the resulting array key;
To speak in code, as follows;
/** * Generate non-repeating random number * @param int $start need to generate the number start range * @param int $end end range * @param int $length The number of random numbers to generate * @return AR Ray generated random number */function Get_rand_number ($start =1, $end =10, $length =4) {$connt = 0; $temp =array (); while ($connt < $length) {$temp []=mt_rand ($start, $end); $data =array_unique ($temp); $connt =count ($data); } sort ($data); return $data;}
Of course, the emphasis is not on this function; The emphasis is on the idea of this function; it can solve many similar problems;
650) this.width=650, "alt=" Bai Jun Remote Blog "src=" http://www.baijunyao.com/Upload/image/ueditor/20151014/1444836221564225. PNG "title=" Bai Jun Haruka Blog "/>
Generate multiple non-repeating random numbers PHP