How can I create a list of random pairs $(x,y)$ where $0<y<x<1$ and $x,y \in \mathbb{R}$ ? I can't seem to place that inequality restriction on the random numbers that are generated.
3 Answers
$\begingroup$
$\endgroup$
RandomReal[1, {100, 2}] /. {x_, y_} /; y > x :> {y, x}
The graphics below confirm that you retain a uniform distribution
$\begingroup$
$\endgroup$
2
Generate random pairs, and reverse-sort each one:
Sort[#, Greater] & /@ RandomReal[1, {10, 2}]
or, for fun, generate two numbers between 0 and 0.5, and add the second to the first:
RandomReal[0.5, {10, 2}].{{1, 0}, {1, 1}}
-
3$\begingroup$ I don't believe the second method is valid: the smaller value can never exceed 0.5, incorrectly ruling out e.g.
{0.8, 0.7}
. $\endgroup$ Jul 25, 2014 at 20:41 -
1$\begingroup$ Note: While the second method has problems the first is correct, and it is four times faster than RunnyKine's (admittedly pretty) method. $\endgroup$ Jul 26, 2014 at 9:52
$\begingroup$
$\endgroup$
6
Another way is
{#, RandomReal[#]} & /@ RandomVariate[TriangularDistribution[{0, 1}, 1], 1000]
To see we do have a uniform distribution:
PDF[
TransformedDistribution[{x, y}, {
x TriangularDistribution[{0, 1}, 1],
y UniformDistribution[{0, b}]
}] /. b -> x,
{x, y}]
-
2$\begingroup$ It looks like that is NOT an uniform distribution. $\endgroup$– SilviaJul 25, 2014 at 20:12
-
$\begingroup$ @Silvia yes it is not uniformly distributed $\endgroup$ Jul 26, 2014 at 3:51
-
2$\begingroup$ Maybe something like
{#, RandomReal[#]} & /@ RandomVariate[TriangularDistribution[{0, 1}, 1], 100000]
? $\endgroup$– SilviaJul 26, 2014 at 8:08 -
$\begingroup$ @Silvia Very good. Either edit this Answer to include that or post your own. $\endgroup$ Jul 26, 2014 at 9:51
-