2014 Mar 21 07:49 PM MDT | Math7 Programming18 [2014]3

For my Grammar bot, I added a new feature: GPS coordinates are added to the tweets. This is just for fun and serves no practical purpose.

However, I wanted the tweets to be uniformly distributed over a sphere. Earth’s shape is not a sphere, but the error is under 1%.

$a$ and $b$ are random values uniformly distributed in $[-1,1]$ $latitude=\theta=\sin^{-1}(u)$
$longitude=\phi=\pi v=(180^{\circ}) v$

According to Wolfram MathWorld, points are randomly distributed over a sphere if:

$\theta$ represents latitude and $\phi$ longitude.
$u$ and $v$ are uniformly distributed in $[0,1]$

$\theta=\cos^{-1}(2u-1)$
$\phi=2\pi v$

Adjusting $u$ and $v$, now distributed in $[-1,1]$, we get: $\theta=\cos^{-1}(u)$
$\phi=\pi (v + 1)$

However, latitude is to be in -90 to 90 degrees, not 0 to 180 degrees, and longitude is to be in -180 to 180 degrees, not 0 to 360 degrees. $\theta=\cos^{-1}(u)-\frac\pi2=-\sin^{-1}u$
$\phi=\pi v$

By spherical symmetry, the negative sign can be removed from latitude, and the distribution will remain the same.