# How can one create random numbers with special correlations?

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:

$$x_1^2+x_2^2=1$$

$$y_1^2+y_2^2+y_3^2=1$$

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?

• 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? – JiK Feb 4 '15 at 11:50
• 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. – LCFactorization Feb 4 '15 at 12:19
• 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. – Myself Feb 4 '15 at 13:00
• 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. – Patrick M Feb 4 '15 at 23:32

## 3 Answers

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.

• I tried to obtain the probability distribution function, and found if $x_1$ is uniformly distributed, so is $\pm \sqrt{1-x_1^2}$ – LCFactorization Feb 4 '15 at 9:36
• 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. – drhab Feb 4 '15 at 9:43
• thank you. I mean $x_i$ not $x_i^2$ is uniformly distributed. – LCFactorization Feb 4 '15 at 9:47
• 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. – drhab Feb 4 '15 at 9:49

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.

• thank you! this is also very useful – LCFactorization Feb 4 '15 at 9:54
• This is very interesting! I wonder if this is true in more than 3 dimensions. – 6005 Feb 4 '15 at 15:23
• @Goos: No. If I'm not mistaken, in $n>1$ dimensions, the distribution of $x$ is proportional $(1-x^2)^{\frac{n-3}{2}}$. – Litho Feb 4 '15 at 15:36
• 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/…. – Ethan Bolker Feb 4 '15 at 22:00

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]$.

• $x_1$ and $x_2$ defined like this are not uniformly distributed. – drhab Feb 4 '15 at 9:59
• This is the way I originally used; and it seems no improvement; $u$ should have pdf like $\frac{1}{\sqrt{1-u^2}}$, – LCFactorization Feb 4 '15 at 10:03
• @drhab: of course not (this is impossible to achieve), but $(x_1,x_2)$ is. – Yves Daoust Feb 4 '15 at 10:23
• 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? – drhab Feb 4 '15 at 10:34