I want to generate events that "arrive" with "t" seconds as mean inter-arrival delay? Starting at time 0, how do I generate the times when the event occurs? Basically, I want to generate sequence of times such as t1, t2, t3, ... when the event occurs. How do I write such a function?
Thank you.
You don't say what language - but take a look at Generate (Poisson?) random variable in real-time
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....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With