88 #define BETA_TURNING_POINT 2
93 #define _Lo(X) (X&_Mask)
94 #define _Hi(X) ((X>>16)&_Mask)
121 *seed= (hi<<16 | lo);
125 static unsigned Scal=0xFFFFFFFF;
134 *seed= (hi<<16 | lo);
135 return( ((
double)*seed)/
Scal );
147 double u1,u2,p1,p2,x;
155 }
while ((x=u1+u2) > 1);
238 while (u == (
double)0)
241 return (-lambda*log(u));
274 #define GAMMA_TURNING_POINT 7
280 double x,y,v,sqrt2a1,asub1,y2;
282 sqrt2a1 = sqrt ((
double)(2*a - 1));
288 if ((x = y2 + asub1) <= 0)
291 if (v <= (1+y*y)*exp((asub1)*log(x/asub1)-y2))
322 double b,p,inva,res=0;
323 double EXP= 2.71828182;
346 res= - log( (b-p)/a);
347 if(
p_dUniform(seed) <= 1.0/pow(res, 1-a))
break;
359 double x,y,v,sqrt2a1,asub1,y2;
361 sqrt2a1 = sqrt (2*A - 1);
367 if ((x = y2 + asub1) <= 0)
370 if (v <= (1+y*y)*exp((asub1)*log(x/asub1)-y2))
397 #define GEOMETRIC_TURNING_POINT 0.38
404 return ((
int) ceil(log (
p_dUniform(seed))/log (1-p)));
429 double p_dNormal (
double mean,
double sigma,
unsigned int *seed)
432 double u1, u2, v1, v2, s;
434 static double x1, x2;
439 return(x2*sigma + mean);
451 s= sqrt( -2*log(s)/s);
456 return( x1*sigma + mean);
462 double total=1, till;
double p_dUniform(unsigned *seed)
unsigned p_iUniform(unsigned *seed)
double p_dNormal(double mean, double sigma, unsigned int *seed)
double p_dBeta(double a, double b, unsigned int *seed)
int p_iPoisson(double mu, unsigned *seed)
#define BETA_TURNING_POINT
double p_dGammaInt(int a, unsigned int *seed)
double p_dGammaGen(double A, unsigned *seed)
double p_dExponential(double lambda, unsigned int *seed)
int p_iGeometric(double p, unsigned int *seed)
#define GAMMA_TURNING_POINT
int p_iBinomial(double p, int n, unsigned int *seed)
#define GEOMETRIC_TURNING_POINT