Skip to content

Commit fe474fd

Browse files
authored
Fix #2425: make rand_in_circle ensure uniform distribution of points (#2426)
1 parent 4b843e1 commit fe474fd

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

arcade/math.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ def rand_in_circle(center: Point2, radius: float) -> Point2:
224224
Generate a point in a circle, or can think of it as a vector pointing
225225
a random direction with a random magnitude <= radius.
226226
227-
Reference: https://stackoverflow.com/a/30564123
228-
229-
.. note:: This algorithm returns a higher concentration of points
230-
around the center of the circle
227+
Reference: https://stackoverflow.com/a/50746409
231228
232229
Args:
233230
center (Point2): The center of the circle
@@ -236,7 +233,7 @@ def rand_in_circle(center: Point2, radius: float) -> Point2:
236233
# random angle
237234
angle = 2 * math.pi * random.random()
238235
# random radius
239-
r = radius * random.random()
236+
r = radius * math.sqrt(random.random())
240237
# calculating coordinates
241238
return (r * math.cos(angle) + center[0], r * math.sin(angle) + center[1])
242239

0 commit comments

Comments
 (0)