Proposition (rejection sampling)
Let $X$ have a density $f$ (which is difficult to sample) and we wish to estimate $\expect g(X)$.
Let $X_1, X_2, \ldots\sim \tilde f$ and $U_1, U_2, \ldots\sim U[0,1]$ all independent such that $f(x) \leq M \tilde f(x)$. Take $$ \begin{align*} K := \min \sb{i\geq 1}{U_i \geq \frac{f(X_i)}{M \tilde f(X_i)}}, \qquad Y := X_K. \end{align*} $$ Then $Y \sim f$.
Note $\expect[K] = \frac{\int M \tilde f(x) \d x}{\int f(x) \d x} = M$.