To generate a random unit vector in RnR^n, the most trivial approach is to use spherical coordinates and generate the angles uniformly at random. Here we introduce another way : sample nn independent identical random variables from Gaussian distribution N(0,1)N(0, 1), denoted as x1,x2,...,xnx_1, x_2, ..., x_n. Then a unit vector vv is obtained by

v=1∑i=1nxi2(x1,x2,...,xn) v = \frac{1}{\sum_{i = 1}^n x_i^2 }(x_1, x_2, ..., x_n)

The key observation is that all points at a fixed distance from the origin is equally generated. To see this, the joints distribution of x1,x2,...,xnx_1, x_2, ..., x_n is given by

p=1(2π)n/2exp⁡(−∑i=1nxi22) p = \frac{1}{(2 \pi)^{n / 2} } \exp \big( - \frac{\sum_{i=1}^n x_i^2 }{ 2 } \big)

pp is fixed when ∑i=1nxi2\sum_{i = 1}^n x_i^2 is fixed.