Leetcode 915 Solution
This article provides solution to leetcode question 915 (generate-random-point-in-a-circle)
Access this page by simply typing in "lcs 915" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/generate-random-point-in-a-circle
Solution
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x = x_center
self.y = y_center
def randPoint(self) -> List[float]:
while True:
x = random.uniform(self.x - self.radius, self.x + self.radius)
y = random.uniform(self.y - self.radius, self.y + self.radius)
if (x - self.x)**2 + (y - self.y) ** 2 > self.radius**2:
continue
return [x, y]
# Your Solution object will be instantiated and called as such:
# obj = Solution(radius, x_center, y_center)
# param_1 = obj.randPoint()