I have a list of numbers between 1-20,000. I wish to insert all of these numbers randomly into a table and only once. How can I accomplish this?
For example with 1-10, they would be inserted in the below order, not 1, 2 , 3, 4
9 3 5 1 2 4 6 ..etc
I have a list of numbers between 1-20,000. I wish to insert all of these numbers randomly into a table and only once. How can I accomplish this?
For example with 1-10, they would be inserted in the below order, not 1, 2 , 3, 4
9 3 5 1 2 4 6 ..etc
you can use Knuths or Floyds algorithm to achieve this and then store all the numbers in the database. Read this SO question for both the implementation:
Unique random numbers in an integer array in the C programming language
One tip, make sure you dont save into the database for every number generated, you should batch your inserts.