Java Generator for Poisson and Uniform Distributions?

master cheif picture master cheif · Apr 15, 2009 · Viewed 27.5k times · Source

From what I understand, the standard generator is for the Normal Distribution. I have to generate random numbers according to the Normal, Uniform and Poisson Distributions, but I can't seem to find a class for the last 2.

I have to generate them in the range of 0 - 999999.

Answer

Simon Nickerson picture Simon Nickerson · Apr 15, 2009

As David has pointed out, the supplied pseudo-random number generator uses the Uniform distribution.

For the other two, I would use the Cern Colt library functions:

These library functions easily allow you to find a random number taken from each distribution, rather than giving you a probability density function or cumulative density function and expecting you to derive the number yourself (which seems to be the Apache Commons-Math approach):

RandomEngine engine = new DRand();
Poisson poisson = new Poisson(lambda, engine);
int poissonObs = poisson.nextInt();

Normal normal = new Normal(mean, variance, engine);
double normalObs = normal.nextDouble();

Also, bear in mind that the Poisson distribution P(λ) for large λ can be approximated very well by the normal distribution N(λ, sqrt(λ)).