Original article: http://www.cnblogs.com/nokiaguy/archive/2008/05/11/1191906.html
10000000 non-repeated random numbers must be generated between 99999999 and 1 million. You can create a table named Table1, which has two fields: the random number field generated (INT type) and the int type field.
Use 99999999-10000000 = 89999999 division 1000000 = 89 (remove ). Then, 10000000 cycles start from 1000000, and 89 is added each time from 10000000,
10000000, 10000089, 10000178...
Then, a random number is generated using newid every cycle, and these two numbers are inserted into Table 1 as values. That is, the first field is inserted with an increment of 89 by step, and the second is the number randomly generated by newid. In this way, Table1 has 1 million records, but the random values are sequential. However, because the second field is random, the value of the first field is random as long as it is sorted by the second field.
In this way, you do not need to check the duplicate value to ensure that you can get 1000000 random numbers without duplicates. They are evenly distributed between 10000000 and 99999999.
Of course, you can also randomly change the 89 step to make it more random.
In this way, you can generate records in batches and insert them into the table. If 1000 such records are generated at a time, the next one thousand records will be generated after insertion. In this way, the task can be completed once every 1000 cycles.