Generate Random Point in a Circle

Medium

Description

Given a circle of radius and center, generate a uniformly random point inside the circle. Implement randPoint().

Examples

Input:radius = 1, x_center = 0, y_center = 0
Output:[random point]
Explanation:

Uniform distribution in circle.

Input:radius = 5, x_center = -2, y_center = 3
Output:[random point within circle]
Explanation:

Generate a uniform random point within a circle of radius 5 centered at (-2, 3). The point must satisfy (x - (-2))² + (y - 3)² ≤ 25, demonstrating how the algorithm works with non-origin centers and larger radius values.

Input:radius = 0.001, x_center = 100, y_center = -50
Output:[random point within circle]
Explanation:

Generate a uniform random point within a very small circle (radius 0.001) centered at (100, -50). This tests the algorithm's precision with a tiny radius near the minimum constraint, where the valid area is extremely small and requires careful handling of floating-point precision.

Constraints

  • 10⁻⁵ ≤ radius ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!