I can't solve the following exercise:

A random number generator generates random values $U \sim \text{U}(0,1)$ from the standard uniform distribution. Use $U$ to generate a random variable $P \sim \text{Pois}(\lambda = 5)$ from a Poisson distribution with rate parameter equal to five.

Comment: In previous tasks I was asked to use $U$ to generate an exponential random variable $E \sim \text{Exp}(\lambda)$. The solution was to take $E \equiv -\tfrac{1}{\lambda} \ln(1-U)$. I think that this can be helpful because of the relation between Poisson distributions and exponential, but I'm not sure.

  • $\begingroup$ Are you required to use your random number generator exactly once per generated Poisson value, or are you allowed to call the rng multiple times per generated Poisson value? $\endgroup$ May 27, 2020 at 1:45
  • $\begingroup$ Try something like: $P=0$ if and only if $U \in (0,e^{-5}]$, $P=1$ if and only if $U \in (e^{-5}, e^{-5}(1+ \frac{5}{2})]$ and in general $P=k$ if and only if $U \in (e^{-5}S_{k-1},e^{-5}S_k]$, where $S_k = \sum_{j=0}^k \frac{5^j}{j!}$. By that $\mathbb P(P=k) = \mathbb P( U \in (e^{-5}S_{k-1},e^{-5}S_k]) = e^{-5}(S_k-S_{k-1}) = e^{-5}\frac{5^k}{k!}$ $\endgroup$
    – Presage
    May 27, 2020 at 1:49
  • $\begingroup$ Quite frankly, a cursory review of the Wikipedia entry en.wikipedia.org/wiki/… should provide all the information you need. $\endgroup$
    – heropup
    May 27, 2020 at 3:51
  • $\begingroup$ Thanks @DominikKutek !! I think that it should say $P=1$ if and only if $U \in (e^{-5},e^{-5}(1+5))$ but I get it, this is so intuitive and so obvious now! Thanks! $\endgroup$
    – lmglm
    May 27, 2020 at 17:58
  • $\begingroup$ @heropup I was looking for an abstract more formal version than an algorithm and that's what you find in popular pages but thanks $\endgroup$
    – lmglm
    May 27, 2020 at 18:00

2 Answers 2


There are many ways to do this; some of which are more computationally efficient than others. If you want to use a single generated value $U \sim \text{U}(0,1)$ then you can use inverse transform sampling using the cumulative distribution function for the Poisson distribution. This gives the output:

$$P \equiv \min \Bigg\{ p =0,1,2,... \Bigg| U \leqslant \exp(-\lambda) \sum_{i=0}^p \frac{\lambda^p}{p!} \Bigg\}.$$

Alternatively, if you are willing to use multiple independent generated values $U_1,U_2,U_3, ... \sim \text{IID U}(0,1)$ then you can use the fact that a Poisson random variable with parameter $\lambda$ is given by the number of sequential events occurring in time $\lambda$ where the times between the events are independent exponential random variables with unit rate. Applying this relationship yields the alternative method:

$$P \equiv \min \Bigg\{ p =0,1,2,... \Bigg| - \sum_{i=1}^p \ln(1-U_i) \leqslant \lambda \Bigg\}.$$

In both cases you can program these with a simple while loop in an appropriate computational platform with a uniform pseudo-random number generator.

  • $\begingroup$ The first with a single uniform was what I was looking for! Inverse transform sampling works great, thanks! $\endgroup$
    – lmglm
    May 27, 2020 at 18:12

You can draw exponentials with mean one. These are the wait times of a Poisson process with rate one. The number of arrivals within time interval of one is Poisson with mean one. So draw exponentials and add them until he sum exceeds one. The total number of times you drew before this happened is going to be Poisson.

So, for instance, if the first exponential is greater than one, then you output zero. If the first exponential is .25 and the second is .8, then you stop cause the total is greater than one and output 1. If the first is .23, the second is. 5, and the third is .3, then you output 2. And so on.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .