3

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?

wiseindy
  • 19,434
  • 5
  • 27
  • 38
  • Are you limited to a single uniform, i.e., inversion, or allowed multiple U's? Your wording sounds like you want a single, but the only techniques I know for the Poisson require multiple U's. – pjs Sep 13 '13 at 13:59

2 Answers2

3

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.

dan3
  • 2,528
  • 22
  • 20
0

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.

Soumendra
  • 1,174
  • 1
  • 15
  • 28