#include #include #include #include #include #include #include #include #include #include #include #define NUM 100000000000 /* MT code */ #define N 624 #define M 397 #define MATRIX_A 0x9908b0df #define UPPER_MASK 0x80000000 #define LOWER_MASK 0x7fffffff #define TEMPERING_MASK_B 0x9d2c5680 #define TEMPERING_MASK_C 0xefc60000 #define TEMPERING_SHIFT_U(y) (y >> 11) #define TEMPERING_SHIFT_S(y) (y << 7) #define TEMPERING_SHIFT_T(y) (y << 15) #define TEMPERING_SHIFT_L(y) (y >> 18) static unsigned long mt[N]; static int mti=N+1; // Random number generator. MUST BE CHANGED TO THE LATEST VERSION LATER. MIGHT BE FASTER void sgenrand(unsigned long seed) { mt[0]= seed & 0xffffffff; for (mti=1; mti= N) { int kk; if (mti == N+1) sgenrand((unsigned long)time(0)); for (kk=0;kk> 1) ^ mag01[y & 0x1]; } for (;kk> 1) ^ mag01[y & 0x1]; } y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1]; mti = 0; } y = mt[mti++]; y ^= TEMPERING_SHIFT_U(y); y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B; y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C; y ^= TEMPERING_SHIFT_L(y); return ( (float)y * 2.3283064370807974e-10 ); } main() { register long int i; time_t t0, t1; clock_t c0, c1; struct timespec ti, tf; t0=time(NULL); c0=clock(); printf("Initial wall time = %ld\t Initial clock time = %d\n",(long)t0,(int)c0); for(i=1;i<=NUM;i++) { Genrand(); } t1=time(NULL); c1=clock(); printf("Final wall time = %ld\t Final clock time = %d\n",(long)t1,(int)c1); printf("Elapsed wall clock time = %ld\n",(long)(t1-t0)); printf("Elapsed CPU time = %f\n",(float)(c1-c0)/CLOCKS_PER_SEC); return(0); }