How to generate random points in a circular distribution

前端 未结 6 1687
执笔经年
执笔经年 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:23

    FIRST ANSWER: An easy solution would be to do a check to see if the result satisfies your equation before proceeding.

    Generate x, y (there are ways to randomize into a select range)

    Check if ((x−500)^2 + (y−500)^2 < 250000) is true if not, regenerate.

    The only downside would be inefficiency.

    SECOND ANSWER:

    OR, you could do something similar to riemann sums like for approximating integrals. Approximate your circle by dividing it up into many rectangles. (the more rectangles, the more accurate), and use your rectangle algorithm for each rectangle within your circle.

提交回复
热议问题