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.
算法来源:Statistical Inference (统计推断,英文版,原书第2版),Chapter5.