How to generate random points in a circular distribution

前端 未结 6 1694
执笔经年
执笔经年 2021-02-02 17:54

I am wondering how i could generate random numbers that appear in a circular distribution.

I am able to generate random points in a rectangular distribution such that

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 18:28

    You can use below the code and if want to learn more https://programming.guide/random-point-within-circle.html

    import random
    import math
    circle_x = 500
    circle_y = 500
    a = random.randint(0,500) * 2 * math.pi
    r = 1 * math.sqrt(random.randint(0,500))
    x = r * math.cos(a) + circle_x
    y = r * math.sin(a) + circle_y
    

提交回复
热议问题