3 #ifndef CH_TOOLS__GB_RAND_HXX 4 #define CH_TOOLS__GB_RAND_HXX 35 long mod_diff(
long x,
long y){
return ((x-y)&0x7fffffff);}
41 for (ii = &A[1], jj = &A[32]; jj <= &A[55]; ii++, jj++)
42 *ii = ((*ii-*jj) & 0x7fffffff);
43 for (jj = &A[1]; ii <= &A[55]; ii++, jj++)
44 *ii = ((*ii-*jj) & 0x7fffffff);
54 long prev = seed,
next = 1;
55 seed = prev = (prev & 0x7fffffff);
57 for (i = 21; i; i = (i + 21) % 55) {
60 next = ((prev-
next) & 0x7fffffff);
62 seed = 0x40000000 + (seed >> 1);
65 next = ((next- seed) & 0x7fffffff);
80 {ind=0;A[0]=-1;
init(seed);}
88 const unsigned long two_to_the_31 = (
unsigned long)0x80000000;
89 unsigned long t = two_to_the_31 - (two_to_the_31 % (
unsigned long)(m));
93 }
while (t <= (
unsigned long) r);
101 return (
double(r)+.5)/double(0x40000000);
105 std::ostream&
save(std::ostream& out)
const 107 for(
int i=0;i<56;i++) out<<A[i]<<
"\n";
108 out<<ind<<
"\n";
return out;
114 for(
int i=0;i<56;i++)