You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/01/31 07:58:46 UTC

cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/random RandomDataImpl.java

psteitz     2004/01/30 22:58:46

  Modified:    math/src/java/org/apache/commons/math/random
                        RandomDataImpl.java
  Log:
  Added bound to simulation loop in nextPoisson().
  
  Revision  Changes    Path
  1.11      +10 -4     jakarta-commons/math/src/java/org/apache/commons/math/random/RandomDataImpl.java
  
  Index: RandomDataImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/random/RandomDataImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RandomDataImpl.java	29 Jan 2004 00:49:01 -0000	1.10
  +++ RandomDataImpl.java	31 Jan 2004 06:58:46 -0000	1.11
  @@ -297,11 +297,15 @@
       }
       
       /** 
  +     * Generates a random long value from the Poisson distribution with the given mean.
  +     * <p>
        * <strong>Algorithm Description</strong>:
        * Uses simulation of a Poisson process using Uniform deviates, as 
        * described 
        * <a href ="http://dmawww.epfl.ch/benarous/Pmmi/interactive/rng7.htm">
  -     * here</a>
  +     * here.</a>
  +     * <p>  
  +     * The Poisson process (and hence value returned) is bounded by 1000 * mean.
        * @param mean mean of the Poisson distribution.
        * @return the random Poisson value.
        */
  @@ -312,9 +316,10 @@
           double p = Math.exp(-mean);
           long n = 0;
           double r = 1.0d;
  +        double rnd = 1.0d;
           Random rand = getRan();
  -        while (true) {
  -            double rnd = rand.nextDouble();
  +        while (n < 1000 * mean) {     
  +            rnd = rand.nextDouble();
               r = r * rnd;
               if (r >= p) {
                   n++;
  @@ -322,6 +327,7 @@
                   return n;
               }
           }
  +        return n;
       }
       
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org