Every sampler starts from uniform random numbers. The transformation method pushes them through an inverse distribution function; rejection sampling throws points uniformly under an envelope kq(z) and keeps those under p̃(z); importance sampling keeps every draw from q but weights it by p̃/q. Watch the acceptance rates and the effective sample size: they tell you how much each method wastes.
Densities: the exponential λe−λy; the Cauchy (1/π)/(1+y2); the gamma Gam(z|a, 1) of (11.15) with the Cauchy envelope of (11.16) centred at c = a − 1 with scale b = √(2a − 1) (times the factor b×) and the smallest k; the two-bump p̃(z) = 0.55 e−(z+2)2/(2·0.752) + 0.45 e−(z−2)2/(2·0.952) of Figures 11.8 and 11.13, with f(z) = tanh(0.6(z+1)). One press of 1 is one proposal (or one uniform), so acceptance rates can be read off directly.
code/ch11_sampling.py (functions exponential_from_uniform, cauchy_from_uniform, box_muller, rejection_sample, adaptive_rejection_sample, importance_sampling, sir; Figures 11.2 to 11.8) and the checks in code/checks_ch11.py. JSRandom(seed) reproduces this page's draws number for number.