If
is a discrete random variable taking on values
, then we can write
.
Implementation of this formula to generate discrete random variables is actually quite straightforward and can be summarized as follows.
To generate
,
- Generate
![U\sim Uniform(0,1)]()
- if
, set
.
we define
and
.
算法来源:Statistical Inference (统计推断,英文版,原书第2版),Chapter5.