views:

247

answers:

1

I'm aware of Knuth's algorithm for generating random Poisson distributed numbers (below in Java) but how do I translate that into calling a method, generateEvent(), randomly over time?

int poissonRandomNumber(int lambda) {
    double L = Math.exp(-lambda);
    int k = 0;
    double p = 1;
    do {
        k = k + 1;
        double u = Math.random();
        p = p * u;
    } while (p > L);
    return k - 1;
}
+1  A: 

Had a little thinking time:

while (true){
    long interval= poissonRandomNumber(5)*1000;
    try {
        Thread.sleep(interval);
        fireEvent();
}
Bedwyr Humphreys