Nothing simpler than the, apart from doing it in 2D. Just choose a random coordinate on each axis using the appropriate dimension of the AABB as the range of possible numbers:
/// <summary>Returns a random point within 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 within the box</returns>
public static Vector3 GenerateRandomPointWithin(
System.Random randomNumberGenerator, Vector3 extents
) {
return new Vector3(
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.X,
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.Y,
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.Z
);
}
/// <param name="randomNumberGenerator">Random number generator that will be used</param>
/// <param name="extents">Extents of the box</param>
/// <returns>A random point within the box</returns>
public static Vector3 GenerateRandomPointWithin(
System.Random randomNumberGenerator, Vector3 extents
) {
return new Vector3(
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.X,
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.Y,
((float)randomNumberGenerator.NextDouble() * 2.0f - 1.0f) * extents.Z
);
}