How do I generate discrete random events with a Poisson distribution?

blank :

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;
}
Jay Elston :

If you are looking to simulate the inter-event arrival time, you want the exponential distribution.

Take a look at Pseudorandom Number Generator - Exponential Distribution

Your code would then look like this:

// Note L == 1 / lambda
public double poissonRandomInterarrivalDelay(double L) {
    return (Math.log(1.0-Math.random())/-L;
}

...

while (true){
    // Note -- lambda is 5 seconds, convert to milleseconds
    long interval= (long)poissonRandomInterarrivalDelay(5.0*1000.0);
    try {
        Thread.sleep(interval);
        fireEvent();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I check whether a scipy distribution is discrete?

How do I generate Log Uniform Distribution in Python?

How to generate a random normal distribution of integers

How do I generate random numbers in Dart?

How do I generate a random int number?

How to generate a random weighted distribution of elements

How to get a random number with a given discrete distribution in Ruby

How to generate random numbers with predefined probability distribution?

How to generate a number representing the sum of a discrete uniform distribution

How do I generate random doubles in an Array?

How do I generate a random num::BigUint?

Random distribution like discrete_distribution<float>

How can I generate n random values from a bimodal distribution in Python?

Given a discrete distribution, how do I round a number to the closest value in that distribution?

How do I generate monthly events?

Boost::random::discrete_distribution How to change weights once constructed

R-How to generate random sample of a discrete random variables?

How to make a random function in fortran to generate the same random distribution into array?

generate poisson distribution using R

How do I generate a sequence of integer numbers in a uniform distribution?

Generate random date ranges where range size is decided from discrete distribution

How do I generate a primary key that is not random?

MatLab:Generate N pseudo-random numbers with a Poisson distribution having mean M and total T where N,M, and T are user defined

Choosing a random value from a discrete distribution

Draw random number using Poisson distribution in Python

how to find expected value of 1000 random number of Poisson Distribution

How to generate a random probability distribution julia

How would I generate a random data series in Python with events?

r generate random poisson values