# How to generate random points uniformly on a circle of radius R?

## Method I: Polar Coordinates

Source

A naive first thought: Oh, we might just generate a uniform random radius $r\in [0,R]$ and a uniform random angle $\theta\in [0,2\pi]$, and we are basically done?

However, if we simulate using this naive method, we will see that points clustered around the center of the circle, as shown in the left picture below:

Something must be wrong.

Key intuition: for a certain angle interval $[\theta, \theta+d\theta]$, there needs to be more points generated further out (at large $r$) than close to zero.

Recall that, in polar coordinates, the infinitesimal area is $rdrd\theta$.

Then, the pdf of $r$ should be proportional to $r$. Actually, it is $f(r)=\frac{2}{R^2}r$ due to normailization.

Now, we can use the inverse cdf to generate $r$:

where $\text{rand()}$ is a uniformly distributed random number in $[0,1]$.

## Method II: Limit Of Shrinking Triangles （Optional）

Think of the circle consisting of an infinite amount of infinitesimal sectors, which is shown below in solid lines. To generate uniform random points in such a sector, we can first generate random points in the parallelogram containing the sector, then fold back those points that fall into the outside triangle as shown below in dotted lines.

Written on December 22, 2017