I am generating a list of coordinates on a square using
#include <random>
using namespace std;
int main(){
random_device rd;
long int seed = rd();
default_random_engine gen(seed);
double max=10.0, min=-10.0;
uniform_real_distribution<double> uni_real(min,max);
double random_x = uni_real(gen);
double random_y = uni_real(gen);
return 0;
}
I would like to ensure that there is a minimum distance between any two points. For my usage, this must hold when periodic boundary conditions are applied.
<random>
library to this. Is there any?O(n^2)
as I am not too concerned with efficiency right now. Unless, there is some easy algorithm to implement that can do this.Other questions around where either dealing with the third point or with other environment from <random>
.
While such sampling (which is equivalent to non-overlapping circles generation) is discussed on math.stackexchange, see https://mathematica.stackexchange.com/questions/2594/efficient-way-to-generate-random-points-with-a-predefined-lower-bound-on-their-p and https://mathematica.stackexchange.com/questions/69649/generate-nonoverlapping-random-circles, I would like to point out to another potential solution which involves quasi-random numbers. For quasi-random Sobol sequences there is a statement which says that there is minimum positive distance between points which amounts to 0.5*sqrt(d)/N
, where d
is dimension of the problem, and N
is number of points sampled in hypercube. Paper from the man himself http://www.sciencedirect.com/science/article/pii/S0378475406002382
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With