/* * (c) 2000 by Antonio Dell'elce (neaya@yahoo.com) * * Just a sample rand func - I like rand funcs ;p * */ #include #include /* we need the binary representation of our floating ops * this function is only used by yrand() but we do some sanity check * anyway.. */ static unsigned long _local_fl2ul (float *F) { if (F) { return *(unsigned long *)F; } else { return -1; } } /* A simple rand function - Weird behavior at times */ unsigned long yrand (void) { static unsigned long _loc; /* Accumulator var... */ float fst; /* Conversion help var */ if (_loc == 0) { _loc = time(0)&3; fst = cos ((time(0) & 0x1E) >> 1); _loc -= _local_fl2ul (&fst); return _loc; } if (_loc & 1) { _loc += 1; fst = sin(-time(0)&0xF); _loc -= (time(0)&0xF) - _local_fl2ul(&fst); } else { _loc += 1; fst = cos ((time (0)&0x1E)>>1); _loc += (time(0)&0xF) * _local_fl2ul(&fst); } return _loc; } int main (int argc, char ** argv) { /* Just a sample of use of the above func... */ printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); printf ("%lx\n", yrand()); return 0; }