摘要:
double cls_random::randomBeta( double alpha, double beta){ /*Johnk's beta generator*/ double u, v; double x, y; do { u=cls_random::randomUniform(); v=cls_random::randomUniform(); x=pow(u,1/alpha); y=pow(v,1/beta); } while (x+y>1); return x/(x+y... 阅读全文
摘要:
double cls_random::randomRayleigh(double sigma){ double pv = sigma*sqrt(-2 * log(cls_random::randomUniform())); return pv;}期望:E=方差:V=wiki:http://zh.wikipedia.org/wiki/%E7%91%9E%E5%88%A9%E5%88%86%E5%B8%83 阅读全文
摘要:
long cls_random::randomPossion(double lambda){ double x = -1, u; double log1, log2; log1 = 0; log2 = -lambda; do { u = cls_random::randomUniform(); log1 += log(u); x++; }while(log1 >= log2); return x; }期望:E=lambda方差:V=lambdawiki:http://zh.wikipe... 阅读全文
摘要:
View Code double cls_random::randomGamma( double alpha, double lambda) { double u, v; double x, y; double b, c; double w, z; bool accept = false; double t; if (alpha > 1.0) { /* Best's rejection algorithm XG for gamma random variates (B... 阅读全文
摘要:
double cls_random::randomX2(int k){ double dv = 0.0; for (int i=0;i<k;i++) { double p_dv = cls_random::randomGaussian_MarsagliaAndBray(0.0,1.0);//默认生成符合标准正态分布的随机数 dv += p_dv*p_dv; } return dv;}期望:E=k方差:V=2kwiki:http://zh.wikipedia.org/wiki/%E5%8D%A1%E6%96%B9%E5%88%86%E5%... 阅读全文
摘要:
View Code long cls_random::randomGeometric( bool shifted, double probability){ long rnd = 0; while(true) { rnd++; double pV = (double)rand()/(double)RAND_MAX; if (pV<probability) { break; } } if (!shifted) { rnd--; }... 阅读全文
摘要:
long cls_random::randomNegativeBinomial( double r, double probability){ long rnd = 0; double fr = 0.0; while(true) { double pV = (double)rand()/(double)RAND_MAX; if (pV<probability) { rnd++; } else { fr++; ... 阅读全文
摘要:
long cls_random::randomBinomial( long N, double probability){ long rnd = 0; for (long i=0;i<N;i++) { double pV = (double)rand()/(double)RAND_MAX; if (pV<probability) { rnd++; } } return rnd;} 期望:E= 方差:V=wiki:http://zh.wikipedia.org/wiki/%E4%BA%8C%E9%A1%B9%E5%88%86%E5%B8%83 阅读全文
摘要:
double cls_random::randomExponential( double lambda){ double pV = 0.0; while(true) { pV = (double)rand()/(double)RAND_MAX; if (pV != 1) { break; } } pV = (-1.0/lambda)*log(1-pV); return pV;} 期望:E= 方差:V=wiki:http://zh.wikipedia.org/wiki/%E6%8C%87%E6%95%B0%E5%88%86%E5%B8%83 阅读全文