= lowerlimit && a[j] < B*lowerlimit ) {
k++;
if( k > MAXA-2000000 ) {
printf( "exceeded hash table size (adding 10%%)\n" );
k += k/10;
goto collision; /* too many iterations */
}
for( i = rint( MAXA*(a[j]/lowerlimit-1) ); 1; i++ ) {
if( i >= MAXA ) i -= MAXA;
if( h[i] == -1.0 ) { h[i] = a[j]; break; }
if( h[i] == a[j] ) goto collision;
}
}
}
}
collision:
tot1 += k;
tot2 += (double)k * (double)k;
printf( "iter %d finished, %d to go, k=%d\n", iter+1, nexp-iter-1, k );
}
var = (nexp*tot2-tot1*tot1) / (nexp-1) / nexp;
ave = tot1/nexp;
printf( "%d tests\n", nexp );
printf( "testing random numbers between %.10g and %.10g\n",
lowerlimit, B*lowerlimit );
printf( "average numbers to a collision: %.5g +- %.5g\n",
ave, sqrt( var/nexp ) * 1.96 );
printf( "observed average corresponds to a size: %.5g\n",
2*ave*ave/Pi - 8/3.0/Pi*ave + (8/9.0/Pi-1/6.0) + 8/135.0/ave );
fr = 2/3.0 + 1.253314137315500251208 * sqrt(n);
fr2 = 2*n + fr;
varfr = fr2 - fr*fr;
stdfr = sqrt(varfr);
printf( "the expected first repetition is %.5g, std=%.5g\n", fr, stdfr );
if( ave >= fr-1.96*stdfr/sqrt(nexp) && ave <= fr+1.96*stdfr/sqrt(nexp) )
printf( "The random number generator passes the test !!!\n" );
else printf(
"The random number generator failed the test by %.5g standard deviations\n",
(ave-fr) / stdfr );
}
/*
Repeating Time Test for U(0,1) Random Number Generators
# Test a U(0,1) (uniformly distributed numbers between 0 and 1)
random number generator to see if it starts repeating when it
is expected to do so.

*by Gaston H. Gonnet*
This is running code to test a random number generator.
See the comments for all details.

© 2003 by Gaston Gonnet, Informatik, ETH Zurich

Last updated on Thu May 4 22:29:26 2003 by
GhG

*/