1. Goal
Generate a random variable satisfying the geometric distribution with parameter :
2. Derivation
由几何分布的含义, 可认为是 次独立实验中首次成功的时间, 且每次实验的成功概率为 , 故有:
Thus generate a random number and let:
Therefore:
Taking log on both sides:
If means the largest integer not greater than , then:
Equivalently: