Is it possible to create uniformly distributed real pseudo random numbers
$x_1,x_2$, and $y_1,y_2,y_3\in$ $[0,1]$, subject to the following constraints:



I tried to use sines and cosines but that does not work; the conventional approach in creating correlated random numbers with a given Pearson correlation coefficient (matrix) via Cholesky decomposition does not seem to suit this situation.

How can one implement it? Is that feasible?

  • $\begingroup$ Do you mean that each of the variables, $x_1$, $x_2$, $y_1$, $y_2$, $y_3$ is uniformly distributed over $[0,1]$ or that the tuple $(x_1, x_2, y_1, y_2, y_3)$ is uniformly distributed over the subset of $\mathbb{R}^5$ defined by the constraints? $\endgroup$
    – JiK
    Commented Feb 4, 2015 at 11:50
  • $\begingroup$ As a matter of fact, I am trying to create uniformly distributed numbers between $[-1,1]$ which are $x_1, x_2$ and $y_1,y_2,y_3$ which subject to the above constraints. $\endgroup$ Commented Feb 4, 2015 at 12:19
  • 1
    $\begingroup$ It would be interesting see a formal proof that what you ask (to give a uniform distribution on a sphere in terms of uniform distributions on a line) is not possible because a sphere is not isometric to a plane. However you can approximate it arbitrarily well by taking a grid on a sphere, such that each cell is approximately rectangular, and divide the unit interval into pieces proportional to the area of the cells to pick a cell. $\endgroup$
    – Myself
    Commented Feb 4, 2015 at 13:00
  • $\begingroup$ Is this equivalent to choosing a random point on a unit circle? For your x set, anyways; for the y set, it would be equivalent to picking a random point on the surface of a sphere, then taking the absolute value to account for your [0,1] interval. Is that what you're trying to accomplish? Because I would think the numbers you wind up with are bound by the geometric relationship these equations embody. In other words, there would be a uniform distribution of numbers of the interval for each variable, but they're not independent. $\endgroup$
    – Patrick M
    Commented Feb 4, 2015 at 23:32

3 Answers 3


As @drhab wrote, it's impossible for two variables. It is possible for three variables, though: an interesting fact is that if you choose a random point on a unit sphere in 3 dimensions (in such a way that it's uniformely distributed over the area), then its $x,y$ and $z$ coordinates are all uniformely distributed over $[-1,1]$. So if $y_1$ and $\phi$ are independent variables, uniformely distributed over $[0,1]$ and $[0,\pi/2]$, correspondingly, and you set $$ y_2 = \sqrt{1-y_1^2}\cos\phi;~~ y_3 = \sqrt{1-y_1^2}\sin\phi, $$ then $y_2$ and $y_3$ are uniformely distributed over $[0,1]$ as well.

  • $\begingroup$ thank you! this is also very useful $\endgroup$ Commented Feb 4, 2015 at 9:54
  • $\begingroup$ This is very interesting! I wonder if this is true in more than 3 dimensions. $\endgroup$ Commented Feb 4, 2015 at 15:23
  • $\begingroup$ @Goos: No. If I'm not mistaken, in $n>1$ dimensions, the distribution of $x$ is proportional $(1-x^2)^{\frac{n-3}{2}}$. $\endgroup$
    – Litho
    Commented Feb 4, 2015 at 15:36
  • $\begingroup$ This follows from a classic calculus problem: The area of a sphere between two parallel planes only depends on the distance between the planes, and the diameter of the sphere. It doesn’t matter where these planes are in relation to the sphere. There are lots of proofs on the web, e.g. usrsb.in/blog/blog/2011/08/11/…. $\endgroup$ Commented Feb 4, 2015 at 22:00

If $x_1^2+x_2^2=1$ and $x_1$ is uniformly distributed over $[0,1]$ then the distribution of $x_2^2=1-x_1^2$ is determined. It is not the same distribution of $z^2$ where $z$ is uniformly distributed over $[0,1]$. So the answer to your "Is it possible..." is: no if it comes to two random numbers. I am not sure about three numbers.

  • $\begingroup$ I tried to obtain the probability distribution function, and found if $x_1$ is uniformly distributed, so is $\pm \sqrt{1-x_1^2}$ $\endgroup$ Commented Feb 4, 2015 at 9:36
  • 5
    $\begingroup$ For $\varepsilon\in\left[0,1\right]$ we have $P\left(z^{2}\leq\varepsilon^{2}\right)=\varepsilon$ and $P\left(1-x_{1}^{2}\leq\varepsilon^{2}\right)=1-\sqrt{1-\varepsilon^{2}}$. Definitely not the same. $\endgroup$
    – drhab
    Commented Feb 4, 2015 at 9:43
  • $\begingroup$ thank you. I mean $x_i$ not $x_i^2$ is uniformly distributed. $\endgroup$ Commented Feb 4, 2015 at 9:47
  • 3
    $\begingroup$ If $x_2$ is uniformly distributed then $x_2^2$ and $z^2$ must have the same distribution. In my comment I show that this is not the case. Conclusion: $x_2$ is not uniformly distributed. $\endgroup$
    – drhab
    Commented Feb 4, 2015 at 9:49

In 2D, using polar coordinates $x_1=\cos 2\pi u,x_2=\sin 2\pi u$, where $u$ is uniform in $[0,1]$.

In 3D, using spherical coordinates $y_1=2\sqrt{v-v^2}\cos 2\pi u, y_2=2\sqrt{v-v^2}\sin 2\pi u, y_3=2v-1$, where $v$ s uniform in $[0,1]$.

  • 1
    $\begingroup$ $x_1$ and $x_2$ defined like this are not uniformly distributed. $\endgroup$
    – drhab
    Commented Feb 4, 2015 at 9:59
  • $\begingroup$ This is the way I originally used; and it seems no improvement; $u$ should have pdf like $\frac{1}{\sqrt{1-u^2}}$, $\endgroup$ Commented Feb 4, 2015 at 10:03
  • $\begingroup$ @drhab: of course not (this is impossible to achieve), but $(x_1,x_2)$ is. $\endgroup$
    – user65203
    Commented Feb 4, 2015 at 10:23
  • $\begingroup$ If not then this does not answer the question of the OP. If $(x_1,x_2)$ is uniformly distributed (as you claim) then what definition do you practicize? Maybe a constant density on some support(here the circle)? Is that commonly accepted as definition of uniform distribution? $\endgroup$
    – drhab
    Commented Feb 4, 2015 at 10:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .