samedi 11 novembre 2017

most efficient way to guarantee uniqueness when generating a large amount of random numbers [duplicate]

This question already has an answer here:

I need to generate an array of random numbers representing v4 ip address, and each random numbers in the array have to be unique.

What would be the most efficient approach (data structure and algorithm) to solve this problem?

I am thinking to generate an array of 255^4 element, from 0 to 255^4. and use a shuffle algorithm such as Fischer and Yattes algorithm to shuffle these number. So when I need to generate an array of n element, I simply pick the 1st n element from the above array.

Is it the most efficient approach?




Aucun commentaire:

Enregistrer un commentaire