3 (source code)

= 3
{scope}

To generate a chi-squared variable with one degree of freedom by the <Marsaglia polar method>, repeatedly draw independent $V,W$ uniformly on $(-1,1)$ until $0<S=V^2+W^2<1$. Return
$$
Z=V\sqrt{\frac{-2\log S}{S}},\qquad Y=Z^2.
$$
The accepted point is uniform on the unit disk; its squared radius is uniform on $(0,1)$ and independent of angle. The radial rescaling gives a standard normal coordinate $Z$, hence \b[$Y\sim\chi_1^2$]. The same accepted pair also supplies another independent standard normal coordinate, if needed. The proof stages below follow the four printed sampler labels.