A donut distribution (for lack of a better term) is a random distribution of points in a 2-dimensional plane, forming a donut-like shape. The distribution is defined by two parameters: the radius r and spread s, in which the distance to the origin follows a normal (Gaussian) distribution around r, with a standard deviation s. The angular distribution is uniform in the range [0,2π).
The challenge
Given a radius r and spread s, your code should yield the Cartesian ((x,y)) coordinates of a single point chosen from this distribution.
Remarks
- Running your code multiple times with the same input should result in the specified distribution.
- Outputting polar coordinates is too trivial and not allowed.
- You can output Cartesian coordinates in any way allowed by the default I/O rules.
- This includes complex values.
Valid approaches
Several algorithms can be used to yield the desired distribution, including but not limited to
- Choose
a from the uniform distribution [0,2π) and b from the normal distribution (r,s).
Let x = b*cos(a) and y = b*sin(a).
- Choose
a from the uniform distribution [0,4) and b from the normal distribution (r,s).
Let x+y*i = b*i^a.
- Choose
a,b,c all from the normal distribution (0,1).
Let d = a+b*i and x+y*i = d/abs(d) * (c*s+r).
Example distributions (N=1000)
Below: r=1, s=0.1
r=1, s=0.1
Below: r=3, s=1
r=3, s=1
Below: r=1, s=0
r=1, s=0
Below: r=100, s=5
r=100, s=5