#include #include "nr.h" using namespace std; DP NR::bnldev(const DP pp, const int n, int &idum) { const DP PI=3.141592653589793238; int j; static int nold=(-1); DP am,em,g,angle,p,bnl,sq,t,y; static DP pold=(-1.0),pc,plog,pclog,en,oldg; p=(pp <= 0.5 ? pp : 1.0-pp); am=n*p; if (n < 25) { bnl=0.0; for (j=0;j= (en+1.0)); em=floor(em); t=1.2*sq*(1.0+y*y)*exp(oldg-gammln(em+1.0) -gammln(en-em+1.0)+em*plog+(en-em)*pclog); } while (ran1(idum) > t); bnl=em; } if (p != pp) bnl=n-bnl; return bnl; }