In the following solution, why is there a sqrt(u)? Since u is just a random number in [0, 1) doesn't getting the sqrt just give you another smaller random number?
To generate points uniformly, randomly, and independently within a circle of radius r around a location (x0, y0), start by generating two independent uniform random values u and v in the interval [0, 1). (This is what almost every random number generator provides you.) Compute
d = r * sqrt(u)
theta = 2 * Pi * v
x = d * cos(theta)
y = d * sin(theta)
The desired random point is at location (x+x0, y+y0).
d
asr*u
, then half of your random points will fall inside a circle of radiusr/2
, which has an area 4 times smaller than a circle of radiusr
. This behavior is not consistent with a uniform random law. So I guess thesqrt
is there to somehow correct this spatial repartition biais.