45

21

Using Mathematica what is an efficient way to generate a list of $n$ **random** two dimensional points $\{x_i,y_i\}$ where $i=1,...,n$ so that **no** two points $p_1$ and $p_2$ in the list has an Euclidean distance lower than say $d$ meaning $\|p_1-p_2\|\leq d$. I came up with the following solution. Though it works I wanted to know if some better method exists.
**Code**

```
NodeGenetrator[LowerBound_, UpperBound_, DistanceBound_,SampleLength_] :=
Block[{list},
list = RandomReal[{LowerBound, UpperBound}, {1, 2}];
For[i = 0, Length@list <= SampleLength - 1, i++,
list = Module[{NewVal, dist},
NewVal = RandomReal[{LowerBound, UpperBound}, 2];
(*NewVal=RandomVariate[NormalDistribution[
Mean@{LowerBound,UpperBound},DistanceBound],2];*)
dist = Map[EuclideanDistance[NewVal, #] &, list];
If[Min[dist] >= DistanceBound,
AppendTo[list, NewVal],
list
]
];
];
list
];
(* Define function parameters *)
LowerBound = 0;
UpperBound = 100;
DistanceBound = 5;
SampleLength = 60;
sample = NodeGenetrator[LowerBound, UpperBound, DistanceBound,SampleLength];
(ListPlot[#, Frame -> True, Axes -> False,PlotStyle -> PointSize[Large],
AspectRatio -> 1] &)@sample
```

**Output**

- As one can see this code uses
`For`

loop and also keeps on iterating until number of points requested is not met. This somehow makes the*execution time*for this function unpredictable! - As expected the parameter
`DistanceBound`

has a important effect on the function behavior. If we try`DistanceBound=12.5`

function evaluation becomes very*time consuming*. - Here we check only one mutual distance condition but is it possible to use a more
*general test function*that checks for more than one mutual characteristics involving those requested number of points that are to be generated.

BR

Perhaps I am getting this backwards, but why not generate random points within a given envelope (say, a circle) and scale the random coordinates with the largest possible distance within that envelope (e.g. the diameter) to your parameter d? Or are p1 and p2 sequential elements of the list? – Yves Klett – 2012-03-05T17:12:08.767

@YvesKlett The elements $p_1$ and $p_2$ are not sequential in the list that we want to generate. They are just arbitrary pair. – PlatoManiac – 2012-03-05T17:18:16.073

3You probably meant

`.. so that NO two points ... has a Euclidean distance lower than say d`

in the second line? – kglr – 2012-03-05T17:18:32.673@kguler Thx for the comment! I corrected my post. – PlatoManiac – 2012-03-05T17:20:42.543

2"Random" does not mean merely arbitrary; nor, in practice, does it mean (merely) that random numbers were involved. To use "random" points,

you need to know their probability distribution.(There exist efficient solutions to this problem having very different distributions.) So: precisely what distribution do you want these points to have? – whuber – 2012-03-05T18:22:56.260@whuber I dont have any special requirement on the distribution any probability distribution should do. You can have a look at the commented part of the code where I use

`NormalDistribution`

. There the variance use used as`DistanceBound`

and mean of the lower and upper bound is chosen as the mean of the distribution. One can usemultipleof the`DistanceBound`

variance to guarantee too many iterations are not needed to achieve the requested sample. If you know any efficient solution please share. – PlatoManiac – 2012-03-05T19:26:50.6403I would like to suggest you

dohave a requirement on the distribution. Otherwise, find two children and ask them to draw pictures of solutions. Check the solutions and digitize them. AskMathematicato choose randomly between the two solutions. After the initial computation of the two solutions, this isextremelyefficient and is obviously random. I'm not being facetious: this is a nice example of a spatial stochastic process that meets every one of your stated requirements. It might help you see why specifying a distribution is important. – whuber – 2012-03-05T20:11:29.7674

For practical solutions which may meet your needs, start with the Wikipedia article on low-discrepancy sequences and then look closely at the Halton sequence.

– whuber – 2012-03-05T21:02:35.740