#define KK 100 /* the long lag */ #define LL 37 /* the short lag */ #define MM 1.0 /* the modulus */ #define mod_diff(x,y) (x+y)-(int)(x+y) /* subtraction mod MM */ double ran_x[KK]; /* the generator state */ void ran_array(aa,n) /* put n new random numbers in aa */ double *aa; /* destination */ int n; /* array length (must be at least KK) */ { register int i,j; for (j=0;j=1.0) ss-=1.0-2*ULP; /* cyclic shift 52 bits */ } for (;j0;j--) xl[j+j]=xl[j],x[j+j]=x[j]; /* "square" */ for (j=KK+KK-2;j>KK-LL;j-=2) xl[KK+KK-1-j]=0.0,x[KK+KK-1-j]=x[j]-xl[j]; for (j=KK+KK-2;j>=KK;j--) if(xl[j]) { xl[j-(KK-LL)]=ULP-xl[j-(KK-LL)], x[j-(KK-LL)]=mod_diff(x[j-(KK-LL)],x[j]); xl[j-KK]=ULP-xl[j-KK],x[j-KK]=mod_diff(x[j-KK],x[j]); } if (is_odd(s)) { /* "multiply by x" */ for (j=KK;j>0;j--) xl[j]=xl[j-1],x[j]=x[j-1]; xl[0]=xl[KK],x[0]=x[KK]; /* cyclic shift of the x array */ if (xl[KK]) xl[LL]=ULP-xl[LL],x[LL]=mod_diff(x[LL],x[KK]); } if (s) s>>=1; else t--; } for (j=0;j