Simulating a Poisson Process

Watch arrivals unfold in real time. This interactive simulation generates exponential interarrival times and builds the counting function N(t) step by step.

Posted on Mathematics Simulation Statistics

In our Poisson process post, we derived the distribution from first principles. We sliced a time interval into infinitely thin slices, assigned a probability to each slice, and took the limit as the number of slices approached \infty. This simulates the process, so you can watch the number of arrivals grow over time.

The Simulation Algorithm

We learned from the exponential distribution that if events arrive at rate λ\lambda, the time between consecutive events follows Exp(λ)\text{Exp}(\lambda). To simulate a Poisson process, we need to generate exponential interarrival times.

The inverse-transform method lets us generate an exponential sample from a uniform random number. Starting with UUniform(0,1)U \sim \text{Uniform}(0, 1), then:

T=lnUλT = -\frac{\ln U}{\lambda}

The random variable TT follows Exp(λ)\text{Exp}(\lambda).

To simulate over an 8-hour window:

  1. Draw U1Uniform(0,1)U_1 \sim \text{Uniform}(0, 1), compute T1=ln(U1)λT_1 = -\frac{\ln(U_1)}{\lambda}. The first arrival is at time S1=T1S_1 = T_1.
  2. Draw U2U_2, compute T2T_2. Second arrival at S2=S1+T2S_2 = S_1 + T_2.
  3. Continue accumulating: Sn=Sn1+TnS_n = S_{n-1} + T_n.
  4. Stop when Sn>8S_n > 8.

That’s the complete algorithm. No approximations, no lookup tables. Uniform random numbers and a logarithm.

The Counting Function N(t)

The Poisson process is usually written as N(t)N(t): the number of arrivals by time tt. It starts at zero, increases by 1 at each arrival, and is constant between arrivals. The resulting graph is a staircase.

The red dashed line shows the expected value: E[N(t)]=λtE[N(t)] = \lambda t. This is the deterministic trend that the random staircase fluctuates around. Sometimes the process runs ahead of expectation, sometimes behind. Over many runs, the average staircase converges to that line.

Interactive Simulation

Press Play to watch the process unfold. The left chart is N(t)N(t): a blue staircase that climbs by one at each arrival. The red dashed line is the theoretical expectation λt\lambda t. The right chart builds an empirical histogram of N(8)N(8) over completed runs, with the theoretical Poisson PMF overlaid in red.

Use Reset to generate a fresh realization and clear the histogram. The speed selector controls how fast the animation runs. Drag the scrub bar to jump to any point in time. Use the λ\lambda slider to change the arrival rate.

Time: 0h 0mArrivals: 0Expected: 0.0
0:00
8:00
expected = 24 arrivals

What to Notice

Connection to Theory

Here’s the connection to the previous post: Fix any time tt and ask: what is N(t)N(t)? It’s a random variable. Each run of the simulation, you get a different value. The distribution of that random variable is exactly Poisson(λt)\text{Poisson}(\lambda t).

P(N(t)=k)=(λt)keλtk!P(N(t) = k) = \frac{(\lambda t)^k e^{-\lambda t}}{k!}

The PMF we derived tells you the probability of landing on each staircase height at time tt. The simulation makes that abstract distribution concrete. When you watch the staircase and notice it usually ends somewhere close to λt=24\lambda t = 24 (given λ=3\lambda = 3, t=8t = 8), and occasionally ends at 18 or 30, you’re seeing the Poisson distribution play out in real time.