// Author: Douglas Wilhelm Harder // Copyright (c) 2012 by Douglas Wilhelm Harder. All rights reserved. #include #include #include #include "Box_muller.h" #include "Central_limit_theorem.h" #include "Marsaglia_polar.h" #include "Ratio.h" int main() { int N = 100000000; srand48( time(NULL) ); double s = drand48(); int t = time(NULL); int i; for ( i = 0; i < N; ++i ) { s += 0.1; } printf( "Default: %d\n", time(NULL) - t ); t = time(NULL); for ( i = 0; i < N; ++i ) { s += randn_bm(); } printf( "Box-Muller method: %d\n", time(NULL) - t ); t = time(NULL); for ( i = 0; i < N; ++i ) { s += randn_clt(); } printf( "Central Limit Theorem: %d\n", time(NULL) - t ); t = time(NULL); for ( i = 0; i < N; ++i ) { s += randn_mp(); } printf( "Marsaglia polar method: %d\n", time(NULL) - t ); t = time(NULL); for ( i = 0; i < N; ++i ) { s += randn_ratio(); } printf( "Ratio method: %d\n", time(NULL) - t ); printf( "%f\n", s ); return 0; }