Geometric distribution
Random variate generation

The geometric distribution can be generated experimentally from i.i.d. standard uniform random variables by finding the first such random variable to be less than or equal to p {\displaystyle p}. However, the number of random variables needed is also geometrically distributed and the algorithm slows as p {\displaystyle p} decreases.

Random generation can be done in constant time by truncating exponential random numbers. An exponential random variable E {\displaystyle E} can become geometrically distributed with parameter p {\displaystyle p} through ⌈ − E / log (1 − p) ⌉ {\displaystyle \lceil -E/\log(1-p)\rceil }. In turn, E {\displaystyle E} can be generated from a standard uniform random variable U {\displaystyle U} altering the formula into ⌈ log (U) / log (1 − p) ⌉ {\displaystyle \lceil \log(U)/\log(1-p)\rceil }.
keywords:frequency