Source: https://cse.buffalo.edu/~hungngo/classes/2011/Spring-694/lectures/sampling.pdf