Generate Random Point in a Circle
Intuition
Solution
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x_center = x_center
self.y_center = y_center
def randPoint(self) -> List[float]:
theta = random.random() * math.pi * 2
r = random.random() ** (1 / 2)
standx = r * math.sin(theta)
standy = r * math.cos(theta)
return self.x_center + self.radius * standx, self.y_center + self.radius * standy
# Your Solution object will be instantiated and called as such:
# obj = Solution(radius, x_center, y_center)
# param_1 = obj.randPoint()