Sign-truncated normal sampling (source code)

= Sign-truncated normal sampling

To draw $N(\mu,1)$ restricted to a positive value, let $a=\Phi(-\mu)$ and return $\mu+\Phi^{-1}(a+(1-a)U)$ for uniform $U\in(0,1)$. For restriction to a negative value use $\mu+\Phi^{-1}(aU)$. These are <inverse transform sampling> constructions. Repeatedly drawing an untruncated normal until its sign agrees is also exact, but inefficient for rare signs.