The easiest solution is to compute the time of the next event based
on the "L" inter-arrival delay. This is based on the cumulative
distribution function for the exponential: F(x) = 1 - e**(-lambda * x)
where lambda is 1/L, the mean time, and x is the amount of time.
This can be solved for x and fed with a uniform random number:
x = -ln(1-U)/lambda where U is a random value 0..1.
From the link 1:
#include <math.h>
#include <stdlib.h>
float nextTime(float rateParameter) {
return -logf(1.0f - (float) random() / (RAND_MAX + 1)) / rateParameter;
}
This link provides a lot of information on how to do it plus examples in
How to Generate Random Timings for a Poisson Process
Note that there are other probability distribution functions that can be used
for event generation (uniform, triangle, etc.). Many of these can be
generated either by code from Boost or by using GNU Scientific Library (GSL).
So to compute times of events:
next_event = time() + nextTime(D);
following_event = next_event + nextTime(D);
If events have a duration, the duration can be another, independent
Poisson distribution, random distribution, fixed interval, etc. However,
will need to check that the interval to the next event is not shorter
than the duration of the event you are simulating:
deltaT = nextTime(MEAN_EVT);
dur = nextTime(MEAN_DUR);
if (deltaT <= dur) {
// either fix duration or get another event....
}