WOLFRAM|DEMONSTRATIONS PROJECT

Acceptance/Rejection Sampling

​
target
Gamma Distribution
optimal c-value is 1.26
current c-value is 1.57
c
sample size
1
generate new sample
start over
histogram
of accepted
of rejected
With this Demonstration, you can visualize the rejection sampling technique, which is also known as the acceptance-rejection algorithm. Select a target distribution (the distribution from which you would like to generate random samples) and then choose a "threshold value"
c
that influences the likelihood that a candidate sample from a nontarget distribution will be "accepted" as if it were, in fact, from the target distribution. You can change the number of random variates generated and view histograms of both the accepted and the rejected samples.
The exponential distribution and the Cauchy distribution for target distributions are supported on the positive half or whole real line, respectively.