Solution (source code)

= Solution

Generate $U\sim\operatorname{Uniform}[0,1]$ and set
$$
X=-\log U.
$$
For $x\geq0$,
$$
\mathbb P(X\leq x)
=\mathbb P(U\geq e^{-x})
=1-e^{-x},
$$
which is the distribution function of an <exponential distribution> with rate one. This is <inverse transform sampling>.