Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a simulator in which I am generating a flow of particle. I want this flow to follow a Poisson process, i.e. $\lambda$ particles are generated per second on average. So how to compute the time of the next particle generation? i.e. how to write the POI function below?

t = POI(lambda)
while true:
    if time_now() >= t:
        t = t + POI(lambda)

According to this post (, I think I should draw a random number $u$ from the $[0,\lambda]$ interval, and compute t so that $f_X(t)=u$, which gives $$ t=\frac{Ln(\lambda/u)}{\lambda} $$

That would make POI be:

    u = random(0,lambda)
    return ln(lambda/u)/lambda

Is that correct?

share|cite|improve this question

The time $T$ to the next event in a Poisson process of rate $\lambda$ has an exponential distribution with rate $\lambda$, so that $P(T \le t) = 1 - e^{-\lambda t}$ for $t \ge 0$. By taking $T = \ln(\lambda/U)/\lambda$ where $U$ is uniform in $(0,\lambda)$, you get $P(T \le t) = P(\lambda/U \le e^{\lambda t}) = P(U/\lambda \ge e^{-\lambda t}) = 1 - e^{-\lambda t}$. So yes, this is correct.

It might be slightly simpler to take a uniform random variable $V$ in $(0,1)$ (corresponding to $U/\lambda$), and thus $T = -\ln(V)/\lambda$.

You should be aware that, depending on the pseudo-random number generator being used, the value returned for a random number in $(0,1)$ may be $0$ (and e.g. a 16-bit generator might return this once in every 65536 calls), which could cause a problem when you try to take the logarithm or the reciprocal of that. To avoid that, you might add some small positive number to your $U$ or $V$, or perhaps just discard a result of $0$ and try again.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.