= Solution
For $\sigma>0$, use the unnormalized normal shape $h(x)=e^{-x^2/(2\sigma^2)}$. The <ratio-of-uniforms method> samples uniformly from
$$
\mathcal A=\{(u,v):0<u<1,\ u^2\leq h(v/u)\}.
$$
Its boundary is $|v|\leq2\sigma u\sqrt{-\log u}$. The largest possible $|v|$ occurs at $u=e^{-1/2}$ and equals $b=\sigma\sqrt{2/e}$, giving the <normal ratio-of-uniforms envelope> $0<u<1$, $-b<v<b$.
Use <independent> uniform pairs to propose $u=U_{2j-1}$ and $v=b(2U_{2j}-1)$. Accept precisely when
$$
\boxed{v^2\leq-4\sigma^2u^2\log u,\qquad\text{then return }X=v/u.}
$$
To verify its distribution, change coordinates from $(u,v)$ to $(u,x)$, with $v=ux$ and <Jacobian determinant> $u$. The accepted point is uniform on $\mathcal A$, and the marginal <probability density function> of $x$ is proportional to
$$
\int_0^{\sqrt{h(x)}}u\,du=\frac12h(x).
$$
Thus the result is $N(0,\sigma^2)$. The region has positive finite area $\sigma\sqrt{\pi/2}$, and the acceptance <probability> is $\sqrt{\pi e}/4$. The case $\sigma=0$ requires simply returning zero.
Back to article page