static int runifx_rng (lua_State *L) { nl_RNG *r = getrng(L); lua_Number low = luaL_optnumber(L, 1, 0); lua_Number high = luaL_optnumber(L, 2, 1); lua_Number range = high - low; if (range < 0) luaL_error(L, "inconsistent parameters: %f > %f", low, high); if (low == 0 && high == 1) setdeviate(number, genrand_res53(r), 3); /* note: [0, 1) */ else setdeviate(number, low + range * genrand_res53(r), 3); return 1; }
double DeskTopSprite::Random_Double( double min,double max ) { double r=genrand_res53(mt); if (min>max) { double t=min; min=max; max=t; } r=min+(r*((max-1)-min+1)); return r; }
int main(){ int nset=NSETS; int ndata=ARRAY_LENGTH; int hash_size=HASH_SIZE; /* double* data; */ double** data2d; char *sdata = "hoge"; /* unsigned long hash,hash2,hash3,hash4; */ unsigned long* hash; unsigned long* hash2; unsigned long* hash3; unsigned long* hash4; int i,j; data2d=(double**) malloc(sizeof(double*)*nset); hash=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash2=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash3=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash4=(unsigned long*) malloc(sizeof(unsigned long)*nset); for(i=0;i<nset;i++){ data2d[i]=(double*) malloc(sizeof(double)*ndata); } /*data=(double*) malloc(sizeof(double)*ndata);*/ init_genrand(194743097); for(j=0;j<nset;j++){ for(i=0;i<ndata;i++){ /* data[i]=genrand_res53(); */ data2d[j][i]=genrand_res53(); } /* hash=adhf_1(data,ndata,hash_size); */ /* hash2=adhf_2(data,ndata,hash_size); */ /* hash3=adhf_3(data,ndata,hash_size); */ /* hash4=adhf_4(data,ndata,hash_size); */ /* printf("%d %d %d %d\n",hash,hash2,hash3,hash4); */ } /*omp parallel start*/ #pragma omp parallel for for(j=0;j<nset;j++){ hash[j]=adhf_1(data2d[j],ndata,hash_size); hash2[j]=adhf_2(data2d[j],ndata,hash_size); hash3[j]=adhf_3(data2d[j],ndata,hash_size); hash4[j]=adhf_4(data2d[j],ndata,hash_size); } /*omp parallel end*/ for(j=0;j<nset;j++){ printf("%d %d %d %d\n",hash[j],hash2[j],hash3[j],hash4[j]); } }
PointColor winner() const { if(!isGameFinished()) return PointColor::EMPTY(); double good_move_count = 0; for(uint i=0; i<mBlackMoves.size(); i++) { if(mBlackMoves[i] == mGoodChoice) { good_move_count++; } } double black_chance = 0.5-SWING/2 + SWING * (good_move_count / mBlackMoves.size()); return genrand_res53() <= black_chance ? PointColor::BLACK() : PointColor::WHITE(); }
double zetarandom(double alpha) { double u, v; double X, T; double test; double b = pow(2.0, alpha - 1.0); do { u = genrand_res53(); v = genrand_res53(); X = floor (pow (u, -1.0 / (alpha - 1.0))); T = pow (1.0 + 1.0 / X, alpha - 1.0); test = v * X * (T - 1.0) / (b - 1.0); } while ( test > (T / b) ); return X; }
int DeskTopSprite::Random_Int(int min, int max) { double min_=min;double max_=max; double r=genrand_res53(mt); if (min_>max_) { double t=min_; min_=max_; max_=t; } min_=ceil(min_); max_=floor(max_); if (min_>max_) return 0; r=min_+floor(r*(max_-min_+1)); return (int)r; }
/// Generates a random number in the interval [0.0, 1.0) with 53-bit resolution /// NOTE: interval is open ended, so 1.0 is excluded /// NOTE: 53 bits is the maximum precision of a double double rnd_uniform53(void) { return genrand_res53(); }
static int Lvaluex(lua_State *L) /** valuex(c) */ { MT *c=Pget(L,1); lua_pushnumber(L,genrand_res53(c)); return 1; }