#include #include #include /* A somewhat more serious randomizer than the typical C rand() function (though its not *that* much more serious) */ unsigned long b0; unsigned long b1 = 14909; // Just some random bits to ensure a non-zero // starting point void CRC63Round(unsigned long *pb0, unsigned long *pb1) { unsigned long L1, L2, L3; unsigned long H1, H2; unsigned long b0, b1; b0 = *pb0; b1 = *pb1; // x = (x>>31)^(x>>30)^(x<<32) (mod 2^63) L1 = (b1<<1)|(b0>>31); L2 = (b1<<2)|(b0>>30); H1 = (b1>>31); H2 = (b1>>30); *pb1 = H1^H2^b0 & 0x7FFFFFFF; *pb0 = L1^L2; } int rand1() { CRC63Round( &b0, &b1 ); return b0&1; } int state = 0; main() { int n,c,v; srand(time(NULL)); b0 = rand(); for( c=0,n=0; n<1000000; n++,c++ ) { // v = rand() & 1; v = rand1(); state = (state + v) & (-v); // printf("%d",v); if( state == 5 ) { // printf("%c",233); c++; state = 0; } // fflush(stdout); } printf("\n%d:%d\n",c,n); }