Exponential-envelope rejection sampling for a chi-squared variable (source code)

= Exponential-envelope rejection sampling for a chi-squared variable
{title2=$\chi^2_\nu$, $\nu\geq2$}

Write $a=\nu/2$. Against an <exponential distribution> proposal of mean $\nu$, the <chi-squared distribution> density has envelope constant $M=a^ae^{1-a}/\Gamma(a)$. The density ratio divided by $M$ is $\exp((a-1)(\log(y/\nu)-y/\nu+1))$. Thus generate $Y=-\nu\log U$ and accept when $\log V\leq(a-1)(\log(Y/\nu)-Y/\nu+1)$ for independent <uniform distributions>. The inequality $\log t\leq t-1$ validates the acceptance probability. The accepted <probability density function> is the target because <rejection sampling> weights the proposal by its target-to-envelope ratio.