Solution (source code)

= Solution

Substitute $x=\sin^2v$, with $0<v<\pi/2$, when integrating the target density. Since $dx=2\sin v\cos v\,dv$, its <cumulative distribution function> is
$$
F(x)=\frac2\pi\arcsin\sqrt{x}\qquad(0<x<1).
$$
Inverting gives the <arcsine distribution> sampler
$$
\boxed{X=\sin^2\left(\frac{\pi U_1}{2}\right).}
$$
The <inverse transform sampling> proof in the root solution shows that it has the required <probability density function>. Use successive independent uniforms for successive samples. A draw at the endpoint one can be discarded if values strictly inside the support are desired; this event has probability zero under the ideal continuous <uniform distribution>.