Imagine you're creating a game where players need to click random locations inside a circular target. You need to ensure these points are uniformly distributed across the entire circle area - not clustered toward the center!
Given a circle defined by its radius and center coordinates (x_center, y_center), your task is to implement a system that generates random points inside this circle with perfect uniform distribution.
Challenge: Simply using random radius and angle won't work - this creates more points near the center because inner rings have less area than outer rings!
Your Task:
- Implement
Solution(radius, x_center, y_center)constructor - Implement
randPoint()that returns[x, y]coordinates - Points on the circumference are considered inside the circle
- Ensure uniform distribution across the entire circle area
Input & Output
Visualization
Time & Space Complexity
Fixed number of operations: 2 random numbers, 1 sqrt, 1 cos, 1 sin
Only stores the circle parameters and temporary variables
Constraints
- 0 < radius β€ 108
- -107 β€ x_center, y_center β€ 107
- At most 3 Γ 104 calls will be made to randPoint
- Points on the circumference are considered inside the circle