Generate Random Point in a Circle LeetCode solution in Python

1
class Solution:
2

3
def __init__(self, radius: float, x_center: float, y_center: float):
4
self.rad = radius
5
self.xc = x_center
6
self.yc = y_center
7

8
def randPoint(self) -> List[float]:
9
while True:
10
xg = self.xc + random.uniform(-1, 1) * self.rad * 2
11
yg = self.yc + random.uniform(-1, 1) * self.rad * 2
12
if (xg - self.xc) ** 2 + (yg - self.yc) ** 2 <= self.rad**2:
13
return [xg, yg]
14

15

16
# Your Solution object will be instantiated and called as such:
17
# obj = Solution(radius, x_center, y_center)
18
# param_1 = obj.randPoint()

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0