Skip to main content
added 35 characters in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).


In response to the comment by Timothy Budd, who wrote: "RandomPoint[Disk[{0, 0}, {a, b}], n] achieves the same result but is over a hundred times faster (for $n=3000$). Of course, this may be just due to low-level optimization."

I think the advantage of Mathematica's command RandomPoint[] over the function QQ[] defined above is mainly due to two things: (i) QQ[] produces (pseudo-)random points one-by-one, whereas RandomPoint[] apparently works with entire lists/arrays and (ii) RandomPoint[Disk[{0, 0}, {a, b}], n] takes into account the knowledge that the region is a (stretched) disk.

The image below of a Mathematica notebook shows that, when QQ[] is modified to a command QQQ[] operating on entire lists, RandomPoint[Disk[{0, 0}, {2, 1}], 3000] is only less than twice$0.0051967/0.0028878<2$ times faster than QQQ[2, 1, 3000]. Moreover, the command RandomPoint[ImplicitRegion[x^2/4 + y^2 <= 1, {x, y}], 3000], which does not let Mathematica know that the region is a (stretched) disk, is 30$0.157363/0.0051967>30$ times slower than QQQ[2, 1, 3000]:

enter image description here

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).


In response to the comment by Timothy Budd, who wrote: "RandomPoint[Disk[{0, 0}, {a, b}], n] achieves the same result but is over a hundred times faster (for $n=3000$). Of course, this may be just due to low-level optimization."

I think the advantage of Mathematica's command RandomPoint[] over the function QQ[] defined above is mainly due to two things: (i) QQ[] produces (pseudo-)random points one-by-one, whereas RandomPoint[] apparently works with entire lists/arrays and (ii) RandomPoint[Disk[{0, 0}, {a, b}], n] takes into account the knowledge that the region is a (stretched) disk.

The image below of a Mathematica notebook shows that, when QQ[] is modified to a command QQQ[] operating on entire lists, RandomPoint[Disk[{0, 0}, {2, 1}], 3000] is only less than twice faster than QQQ[2, 1, 3000]. Moreover, the command RandomPoint[ImplicitRegion[x^2/4 + y^2 <= 1, {x, y}], 3000], which does not let Mathematica know that the region is a (stretched) disk, is 30 times slower than QQQ[2, 1, 3000]:

enter image description here

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).


In response to the comment by Timothy Budd, who wrote: "RandomPoint[Disk[{0, 0}, {a, b}], n] achieves the same result but is over a hundred times faster (for $n=3000$). Of course, this may be just due to low-level optimization."

I think the advantage of Mathematica's command RandomPoint[] over the function QQ[] defined above is mainly due to two things: (i) QQ[] produces (pseudo-)random points one-by-one, whereas RandomPoint[] apparently works with entire lists/arrays and (ii) RandomPoint[Disk[{0, 0}, {a, b}], n] takes into account the knowledge that the region is a (stretched) disk.

The image below of a Mathematica notebook shows that, when QQ[] is modified to a command QQQ[] operating on entire lists, RandomPoint[Disk[{0, 0}, {2, 1}], 3000] is only $0.0051967/0.0028878<2$ times faster than QQQ[2, 1, 3000]. Moreover, the command RandomPoint[ImplicitRegion[x^2/4 + y^2 <= 1, {x, y}], 3000], which does not let Mathematica know that the region is a (stretched) disk, is $0.157363/0.0051967>30$ times slower than QQQ[2, 1, 3000]:

enter image description here

added 1115 characters in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).


In response to the comment by Timothy Budd, who wrote: "RandomPoint[Disk[{0, 0}, {a, b}], n] achieves the same result but is over a hundred times faster (for $n=3000$). Of course, this may be just due to low-level optimization."

I think the advantage of Mathematica's command RandomPoint[] over the function QQ[] defined above is mainly due to two things: (i) QQ[] produces (pseudo-)random points one-by-one, whereas RandomPoint[] apparently works with entire lists/arrays and (ii) RandomPoint[Disk[{0, 0}, {a, b}], n] takes into account the knowledge that the region is a (stretched) disk.

The image below of a Mathematica notebook shows that, when QQ[] is modified to a command QQQ[] operating on entire lists, RandomPoint[Disk[{0, 0}, {2, 1}], 3000] is only less than twice faster than QQQ[2, 1, 3000]. Moreover, the command RandomPoint[ImplicitRegion[x^2/4 + y^2 <= 1, {x, y}], 3000], which does not let Mathematica know that the region is a (stretched) disk, is 30 times slower than QQQ[2, 1, 3000]:

enter image description here

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).


In response to the comment by Timothy Budd, who wrote: "RandomPoint[Disk[{0, 0}, {a, b}], n] achieves the same result but is over a hundred times faster (for $n=3000$). Of course, this may be just due to low-level optimization."

I think the advantage of Mathematica's command RandomPoint[] over the function QQ[] defined above is mainly due to two things: (i) QQ[] produces (pseudo-)random points one-by-one, whereas RandomPoint[] apparently works with entire lists/arrays and (ii) RandomPoint[Disk[{0, 0}, {a, b}], n] takes into account the knowledge that the region is a (stretched) disk.

The image below of a Mathematica notebook shows that, when QQ[] is modified to a command QQQ[] operating on entire lists, RandomPoint[Disk[{0, 0}, {2, 1}], 3000] is only less than twice faster than QQQ[2, 1, 3000]. Moreover, the command RandomPoint[ImplicitRegion[x^2/4 + y^2 <= 1, {x, y}], 3000], which does not let Mathematica know that the region is a (stretched) disk, is 30 times slower than QQQ[2, 1, 3000]:

enter image description here

added 1 character in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{u,v)\in D\colon u\le x\}$$\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{u,v)\in D\colon u\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).

A quick way to generate a random point uniformly distributed in a bounded region $D$ is to generate a random point $P$ uniformly distributed in a rectangle $R$ containing $D$ and, if $P\notin R$, then discard $P$ and continue until you have as many random points as you want.

For instance, here is the generation (in Mathematica) of $3000$ random points uniformly distributed inside the ellipse centered at the origin with half-axes $a=2$ and $b=1$:

enter image description here

Here the "waste" fraction is $1-\frac{\pi ab}{4ab}\approx0.21$, about $21\%$, no problem at all.


Alternatively, one may generate a random point uniformly distributed in an arbitrary measurable plane region $D$ of positive area without any waste, as follows. For real $x$, let $$F(x):=F_D(x):=\frac{A(x)}{A(\infty)},$$ where $A(x)$ is the area of the region $\{(s,t)\in D\colon s\le x\}$. So, $F$ is a cumulative probability distribution function (cdf), which is actually the cdf of the abscissa of a random point uniformly distributed in $D$. For any $u\in(0,1)$, let $$F^{-1}(u):=\min\{x\in\mathbb R\colon F(x)\ge u\},$$ the quantile function corresponding to $F$. So, if $U$ is a random variable (r.v.) uniformly distributed on the interval $(0,1)$, then the distribution of the r.v. $$X:=F^{-1}(U)$$ will coincide with the distribution of the abscissa of a random point uniformly distributed in $D$.

If now the conditional distribution of a r.v. $Y$ given $X=x$ is the uniform distribution on the one-dimensional set $$D_x:=\{y\in\mathbb R\colon(x,y)\in D\},$$ then the random point $(X,Y)$ will be uniformly distributed in $D$.

So, the generation of a $(X,Y)$ uniformly distributed in $D$ is reduced to the generation of two random points on the real line.

For instance, here is the generation (in Mathematica) of $2000$ random points uniformly distributed in the ellipse $E:=\{(x,y)\in\mathbb R^2\colon100 (x - y)^2 + (x + y)^2 \le4\}$:

enter image description here

Here there is no "waste" at all, but the volume of calculations is much greater than in the previous example. In this particular case, it would be more economical to rotate the ellipse appropriately to make its axes horizontal and vertical and then use the approach of the previous example (without rotation, there could be too much waste).

added 621 characters in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229
Loading
added 1194 characters in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229
Loading
added 353 characters in body
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229
Loading
Source Link
Iosif Pinelis
  • 127.7k
  • 8
  • 107
  • 229
Loading