I have a large 2 dimensional grid, let us say 10000 X 10000. From these grid I need to select 1000 random points but I also need to take care that none of the two points are the same. The standard way that comes to my mind is after selecting every point I should check all the previous entries to see if that point has already been selected or not but it seems for large grids and large number of points this will become inefficient. Is there a better way to do it?
I am using C++
I have a large 2 dimensional grid, let us say 10000 X 10000. From
Share
Randomly selecting any point and then discarding it if it exists in the Selected Points list should not be inefficient, so long as you have well sorted collection of Selected Points, that you can also easily insert into.
Also, depending on how your points are defined (i.e. are they each associated with a class or struct that you’ve defined), you could add a boolean variable to the point object, named
Selected. Once you select a point, check to see if it has been marked asSelected. If not, add it to your list and change theSelectedvalue toTRUE. Otherwise, continue on with your selection of random points.