Java Generator for Poisson and Uniform Distributions?

前端 未结 4 1171
野性不改
野性不改 2020-12-08 17:56

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,

4条回答
  •  清歌不尽
    2020-12-08 18:27

    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:

    • Poisson
    • Normal/Gaussian

    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(λ)).

提交回复
热议问题