Simulating
X~f(x)
is equivalent to simulating
(X,U)~U{(x,u):0<u<f(x)}
If g is such that f/g is bounded, and therefore we can find a value M such that M*g(x)>=f(x) for all x, then we can simulate from f as follows:
1. Generate Y from density g, and U from Uinform(0,1).
2. If U<=f(Y)/Mg(Y), set X=Y. Otherwise, return to step 1.