In general, the conversion function between two distributions g(x) and h(y) is,

\displaystyle g(x)dx=h(y)dy

By integration on both side, we have

\displaystyle G(x) = H(y) \Rightarrow y=H^{-1}(G(x))=f(x)

We are going to show a generation of uniform distribution on a Disk first. We set the distribution g(x) = 1 be a uniform distribution form (0,1). From the polar coordinate, we have,

\displaystyle dx dy=rdrd\theta

the right side is the unit area element in polar coordinate. We can set dy = d\theta, h(r) = r, thus,

\displaystyle H(r) = r^2/2 \Rightarrow x=r^2/2 \Rightarrow f(x)=\sqrt(2x)

in Mathematica,

n=10000;
θ=RandomReal[{0,2 pi},n];
f[x_]:=Sqrt[x];
r=Table[f[RandomReal[{0,1}]],{i,1,n}];
disk=Table[r[[i]]{Cos[θ[[i]]],Sin[θ[[i]]]},{i,1,n}]
ListPlot[disk]

Screenshot from 2016-01-29 17:00:46.png

 

Similarly, For a uniform sphere,

\displaystyle dxdydz=r^2dr \sin(\theta)d\theta d\phi

Thus we have,

\displaystyle f_{r}(x) = (3x)^{1/3}, f_{\theta}(y)=\cos^{-1}(2y-1), f_{\phi}(z)=z