Assume that you have a random number generator which gives you (i.e. uniform distribution on the interval ) and a cumulative distribution function . Assume for simplicity that is strictly increasing, so that is well-defined as a functional inverse. Inverse transform sampling allows us to use this set-up to draw samples from : If then . Thus, we can take to be our sample.
(If is not strictly increasing, we can take .)
Did you know that we can modify this slightly to draw samples , conditional on , where ? Instead of taking as the sample, take instead.
Here is the proof: Let be the CDF of given . Then if , and for , .
Now, for any ,
which means that has the same distribution as , i.e. (by an application of inverse transform sampling).