To sample a random variable X with density f(x) we introduce an auxiliary variable Y and iterate as follows: Given a sample x we choose y uniformly at random from the interval [0, f(x)]; given y we choose x uniformly at random from the set f^{-1}[y, f(x)]. The sample of x is obtained by ignoring the y values.
Example
To sample from the normal distributionN(0,1) we first choose an initial x -- say 0. After each sample of x we choose y uniformly at random from [0, e^{-x^2/2}/\sqrt{2\pi}]; after each y sample we choose x uniformly at random from [-\alpha, \alpha] where \alpha = \sqrt{-2\ln(y\sqrt{2\pi})}.