While this looks like a basic problem, it is actually somewhat more complicated than expected. One might think of generating uniform deviates for the longitude, as well as uniform deviates for the latitude. This will over-sample near the poles and under-sample near the equator: the resulting point distribution won't be uniform on the surface of the sphere. This has serious implications if one wants to measure (say) the average temperature on Earth using (say) 1,000 random locations. If these locations are not random, it will introduce a bias.

How do we fix this problem?

One easy way to produce random points uniformly distributed on a sphere centered at the origin, of radius 1, is to

First simulate uniform deviates on the cube [-1, 1] x [-1, 1] x [-1, 1] Discard the points that fall outside the sphere Project all remaining points (those located inside the sphere) on the surface of the sphere

The classic solution is different but produces the same uniform distribution on the sphere:

Generate three random numbers (x, y, z) using Gaussian distribution Multiply each number by 1 / SQRT(x^2 + y^2 + z^2)

Note that step #2 in the second algorithm is identical to step #3 in the first algorithm.

Related article