/*Bibliotheque de generateur de nombres aleatoires. D'apres Knuth et NR */ #define KK 100 /* the long lag */ #define LL 37 /* the short lag */ #define mod_sum(x,y) (((x)+(y))-(int)((x)+(y))) /* (x+y) mod 1.0 */ int premiere_util=1; double ran_u[KK]; /* the generator state */ void ranf_array(double aa[], int n) /* put n new random fractions in aa */ { register int i,j; for (j=0;j=1.0) ss-=1.0-2*ulp; /* cyclic shift of 51 bits */ } for (;j0;j--) ul[j+j]=ul[j],u[j+j]=u[j]; /* "square" */ for (j=KK+KK-2;j>KK-LL;j-=2) ul[KK+KK-1-j]=0.0,u[KK+KK-1-j]=u[j]-ul[j]; for (j=KK+KK-2;j>=KK;j--) if(ul[j]) { ul[j-(KK-LL)]=ulp-ul[j-(KK-LL)], u[j-(KK-LL)]=mod_sum(u[j-(KK-LL)],u[j]); ul[j-KK]=ulp-ul[j-KK],u[j-KK]=mod_sum(u[j-KK],u[j]); } if (is_odd(s)) { /* "multiply by z" */ for (j=KK;j>0;j--) ul[j]=ul[j-1],u[j]=u[j-1]; ul[0]=ul[KK],u[0]=u[KK]; /* shift the buffer cyclically */ if (ul[KK]) ul[LL]=ulp-ul[LL],u[LL]=mod_sum(u[LL],u[KK]); } if (s) s>>=1; else t--; } for (j=0;j=0? *ranf_arr_ptr++: ranf_arr_cycle()) double ranf_arr_cycle() { ranf_array(ranf_arr_buf,QUALITY); ranf_arr_buf[100]=-1; ranf_arr_ptr=ranf_arr_buf+1; return ranf_arr_buf[0]; } double hasard() { if(premiere_util) { ranf_start(1); premiere_util=0; } return ranf_arr_next(); } void forceinit(long rac) { premiere_util=0; ranf_start(rac); }