Reputation: 19655
I have to write a C program to convert a uniform distribution of random numbers (say from 0 to 1) to a poisson distribution. Can anyone help?
Upvotes: 3
Views: 2538
Reputation: 1192
I am assuming you want to write a C program that can sample a random number from the Poisson Distribution, given a random number in U(0,1).
Generally, this is done by taking the inverse CDF of the number from U(0,1). For discrete distributions like Poisson, one first transforms it to a continuous distribution by assuming that the CDF function is smooth between the integer points, and then we apply appropriate approximations (floor function).
The book Numerical Recipes in C++ (3rd Ed) has the complete explanation and C++ code as well. sec 7.3.12, page 372.
Upvotes: 0
Reputation: 2559
Use GSL, the Gnu Scientific Library. There's a function called gsl_ran_poisson:
This function returns a random integer from the Poisson distribution with mean mu. The probability distribution for Poisson variates is, p(k) = {\mu^k \over k!} \exp(-\mu) for k >= 0.
Otherwise, look at the code and copy the ideas.
Upvotes: 3