Bug in bnldev (Binomial deviates) function?


davidVickers
11-25-2010, 09:33 AM
To the NRF community,

I am having a problem with the binomial distribution generator routine "bnldev". Whenever the integer argument passed to bnldev, n, exceeds a very large value, say 17664979, it appears to get stuck in a seemingly never-ending loop.

I've managed to determine the source of the problem occurs when the variable t in the final while-loop:

while (ran1 (idum) > t)

is assigned 0.0000 or a very small value, where it likely gets truncated as floating point. When this happens, the condition of this while-loop remains true. Has anyone on the forum encountered a similar problem? If so, has a solution been posted? Any suggestions will be greatly appreciated!

Cheers,

davidVickers

Bill Press
11-25-2010, 02:36 PM
This bug doesn't occur in the current, 3rd edition, version, which uses the ratio-of-uniforms method (with inner and outer squeezes) instead of the rejection method on a Lorentzian. For use in C or Fortran, you might want to port that code from the newer C++.