# How to generate arrivals around a Poisson distribution

I'm interested in generating random arrivals that should simulate the call arrivals of a call center. I chose to use a Poisson distribution, but the greatest problem comes with the fact that it's a discrete distribution.

So I thought that I could use it to generate an arrival rate in a time frame of 1 second; this way every second I re-compute the arrival rate, and spread every call in this frame of time.

But the problem is: to generate calls with a realistic rate, how should I "spread" the calls? I mean: if for example between a time frame of [4.0, 5.0], the generated arrival rate is 5, to just generate every calls every 0.2 seconds (arrivals: 4.0,4.2,4.4,4.6,4.8) is unrealistic.

A second problem comes with the fact that in reality the variance is much greater than the mean, but in a poisson process they're equal. A workaround could be to general arrival rates in a larger time frame, so that the variance increases, but this would make the process not homogeneous. Suggestions?

• Do you want to generate a set of counts (eg, 9 calls came in Tuesday), or a set of times (eg, a call a 8:53 am, 9:45 am, etc)? – gung - Reinstate Monica Feb 4 '15 at 22:21
• See stats.stackexchange.com/questions/129322/… for a detailed solution with step-by-step explanations. The Poisson arrival times are generated all at once with the single line of R code CUSTOMERS["Arrived", ] <<- cumsum(round(rexp(n.events, arrival.rate), 2)) – whuber Feb 4 '15 at 22:50

1. If it's a Poisson process, the inter-call time is exponential with mean equal to the inverse of the rate. It's probably easier at each step to simply generate the time to the next call than generate a number of calls in an interval and then try to place them in that interval.

If you really want do it the way you were saying, you'd use a uniform distribution to place their time within each interval. Just generate a standard random uniform for each one, and that's the fraction of the way through the interval that it happened at.

2. You can get larger variance either because there's heterogeneity of rates or because of some kind of dependence. You need to consider which change from a Poisson process might be more appropriate for your situation, and in what manner.

For example, you can get heterogeneity of rates because different time periods just tend to get more calls (e.g. more calls per hour in the late afternoon than the early morning). Or calls might tend to come in clusters (e.g. a TV ad might generate a burst of calls, but the appearance of the ad might happen any time). Or people might often tend to call back several times within a single day, but then not call again for a long time.

• +1 Method (1) (accumulating independent exponential variates) is readily adapted to inhomogeneous Poisson processes where the rate is a function of the time (or of any other information available within the simulation up to that time): just compute the current value of the rate and generate the time to the next event using that rate. – whuber Feb 4 '15 at 22:54
• I still seem to be typing 'homo' when I mean 'hetero'. I don't know what the source of that particular tendency is. Good thing this isn't a dating site. – Glen_b Feb 4 '15 at 23:08
• @Glen_b comment of the year. – Reinstate Monica Feb 5 '15 at 0:25

The key to efficiently generating poisson distributed events is to realize the any number of events that exist within any interval occur independently. In other words,the occurrence time of each event is uniformly distributed in the interval. Each of n events with average arrival rate of mu occur uniformly in the interval (0 to n/mu). Simply generate n events randomly in this interval. Then place them in an ordered array.

Let mu equal the arrival rate per time interval. Let n equal the number of events to generated. The total time span is n/mu. The time distribution of events will approximate the Poisson distribution as n approaches infinity. In Python the algorithm is as follows:

#generate 10000 events with a mu of 5.0 events per unit time
import random
#n is the number of events to generate.
mu=5.0
n=10000
#time span is n/mu
time_span=n/mu
events=[]
#place n events uniformly distributed and place in array events.
for j in range(0,n)  :
events.append(random.random())
#sort the array
events.sort()

#at this point the events array contains n events distributed from
#(0.0 to 1.0). The next step is to scale the timing of all events by multiplying
#by n/mu which is the total time span of events.
for j in range(0,n)  :
events[j]*=time_span
#The events array now contains an array of event times which are approximate the #Poisson distribution with a mean arrival rate of mu per time interval.
#This has been tested using a chi squared test and closely approximates the
#Poisson Distribution.