Random Points on Sphere Surface

Distributing points randomly on a sphere doesn't seem to be a real problem at first. Just generate random values for latitude and longitude, then convert that into cartesian coordinates. The problem with that method is that the points would be more dense at the poles of the sphere. The reason is that if you walk 45 longitudal degrees on the equator of the sphere, you have covered a much larger distance than if you walk 45 longitudal degrees near the pole.

The solution to obtain uniform distribution then is to increase the probability with which points are placed near the equator:

/// <summary>Returns a random point on the surface of a sphere</summary>
/// <param name="randomNumberGenerator">Random number generator that will be used</param>
/// <param name="radius">Radius of the sphere</param>
/// <returns>A random point on the sphere's surface</returns>
public static Vector3 GenerateRandomPointOnSurface(
  System.Random randomNumberGenerator, float radius
) {

  // Choose a random longitude for the point
  float phi = (float)randomNumberGenerator.NextDouble() * MathHelper.TwoPi;

  // The z axis goes straight through the sphere and is chosen in random.
  float z = (float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f;

  // From that, we'll calculate the latitude this point will have on the
  // sphere's surface.
  float theta = (float)Math.Sqrt(1.0f - z * z);

  // Calculate the final position of the point in world space
  return new Vector3(
    radius * theta * (float)Math.Cos(phi),
    radius * theta * (float)Math.Sin(phi),
    radius * z
  );

}