Random Points on AABB Surface

To actually obtain an equal distribution of points is harder than it seems since the AABB's six faces come in three different sizes. So we need to calculate the total surface area of the AABB and choose which side we generate a point on by using a random number up in the range of that surface area to decide.

/// <summary>Returns a random point on the surface of a box</summary>
/// <param name="randomNumberGenerator">Random number generator that will be used</param>
/// <param name="extents">Extents of the box</param>
/// <returns>A random point on the box' surface</returns>
/// <remarks>
///   The performance of this algorithm varies slightly depending on the face
///   that is chosen for the random point because a different number of
///   comparisons and subtractions will be performed.
/// </remarks>
public static Vector3 GenerateRandomPointOnSurface(
  System.Random randomNumberGenerator, Vector3 extents
) {

  // For this task, we also need the dimensions of the box
  Vector3 dimensions = extents * 2.0f;

  // Determine the area covered by the sides of the box
  float leftRightArea = dimensions.Z * dimensions.Y;
  float topBottomArea = dimensions.X * dimensions.Z;
  float frontBackArea = dimensions.X * dimensions.Y;

  // Choose which face of the box the point is going be on
  float side = (float)randomNumberGenerator.NextDouble() *
    (leftRightArea * 2.0f) * (topBottomArea * 2.0f) * (frontBackArea * 2.0f);

  // Now obtain were the point will be located
  float u = (float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f;
  float v = (float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f;

  // Calculate the final world space coordinates of the point
  side -= leftRightArea;
  if(side < 0.0)
    return new Vector3(-extents.X, v * extents.Y, u * extents.Z);

  side -= leftRightArea;
  if(side < 0.0)
    return new Vector3(+extents.X, v * extents.Y, u * extents.Z);

  side -= topBottomArea;
  if(side < 0.0)
    return new Vector3(u * extents.X, +extents.Y, v * extents.Z);

  side -= topBottomArea;
  if(side < 0.0)
    return new Vector3(u * extents.X, -extents.Y, v * extents.Z);

  side -= frontBackArea;
  if(side < 0.0)
    return new Vector3(u * extents.X, v * extents.Y, -extents.Z);

  else
    return new Vector3(u * extents.X, v * extents.Y, +extents.Z);
}