Generating random, non-repeating points on the plane - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-19T20:07:31Z https://mathematica.stackexchange.com/feeds/question/198562 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/198562 3 Generating random, non-repeating points on the plane Friasco https://mathematica.stackexchange.com/users/47644 2019-05-17T11:51:42Z 2019-05-17T14:21:40Z <p>The problem is to generate random points on the plane that are unique (i.e. no repetition of a point). The following won't work because of repetition:</p> <pre><code>In:= RandomInteger[5, {3, 2}] Out= {{1, 3}, {3, 5}, {1, 3}} </code></pre> <p>So RandomSample may be the answer. But something like the following also repeats:</p> <pre><code>In:= Table[RandomSample[Range, 2], {3}] Out= {{3, 4}, {4, 5}, {3, 4}} </code></pre> <p>Is there a clever solution to this?</p> https://mathematica.stackexchange.com/questions/198562/-/198563#198563 7 Answer by Slepecky Mamut for Generating random, non-repeating points on the plane Slepecky Mamut https://mathematica.stackexchange.com/users/48033 2019-05-17T11:59:13Z 2019-05-17T11:59:13Z <p>Better is</p> <pre><code>RandomSample[Tuples[Range, 2], 3] </code></pre> <p>Your formula may generate the same point two-times or more</p> <p>(try, for a counterexample </p> <pre><code>Table[RandomSample[Range, 2], {3}] </code></pre> <p>)</p> https://mathematica.stackexchange.com/questions/198562/-/198566#198566 3 Answer by MikeY for Generating random, non-repeating points on the plane MikeY https://mathematica.stackexchange.com/users/47314 2019-05-17T12:54:02Z 2019-05-17T14:21:40Z <p>Another approach...if you want 10 points in a 3D space, with no repeats of a coordinate in any dimension...</p> <pre><code>dim = 3; numPts = 10; Transpose@(Ordering /@ Ordering /@ RandomReal[1, {dim, numPts}]) </code></pre> <p><span class="math-container">$\begin{array}{ccc} 8 &amp; 6 &amp; 4 \\ 7 &amp; 5 &amp; 8 \\ 2 &amp; 4 &amp; 1 \\ 5 &amp; 8 &amp; 5 \\ 9 &amp; 3 &amp; 2 \\ 10 &amp; 7 &amp; 9 \\ 1 &amp; 2 &amp; 10 \\ 4 &amp; 1 &amp; 7 \\ 6 &amp; 9 &amp; 6 \\ 3 &amp; 10 &amp; 3 \\ \end{array}$</span></p> <p>Data sets in this form (each column is a permutation of Range[numPts]) have a bunch of interesting combinatorial properties. What is fascinating is to take the transform and apply it to random data that is distributed in unique ways, such as points on a simplex, hypersphere, etc.</p> <p>Expanding a wee bit: the reason this transformation is interesting is that in algorithms to identify the Pareto frontier, you don't care about absolute values of a coordinate, just its ordinal value with respect to other values in a column. Once transformed, a bunch of shortcuts and interesting properties open up.</p>