diff -r b71f8ff62046 -r e92071fadd3f lemon/bits/mingw32_rand.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/bits/mingw32_rand.cc Mon Apr 03 19:47:37 2006 +0000 @@ -0,0 +1,83 @@ +#ifdef WIN32 + +#include + + +static unsigned short _mingw_rand_state[10]; + +void _mingw_rand_next_state(unsigned short xsubi[3]) { + _mingw_rand_state[8] = _mingw_rand_state[9] = 0; + _mingw_rand_state[7] = _mingw_rand_state[6]; + for (int i = 0; i < 3; ++i) { + unsigned long val = 0; + for (int j = 0; i + j < 3; ++j) { + val += (unsigned long)_mingw_rand_state[7 + i + j] + + (unsigned long)xsubi[i] * (unsigned long)_mingw_rand_state[3 + j]; + _mingw_rand_state[7 + i + j] = val; + val >>= 16; + } + } + xsubi[0] = _mingw_rand_state[6]; + xsubi[1] = _mingw_rand_state[7]; + xsubi[2] = _mingw_rand_state[8]; +} + +long int lrand48(void) { + return nrand48(_mingw_rand_state); +} + +long int nrand48(unsigned short xsubi[3]) { + _mingw_rand_next_state(xsubi); + return ((long)(xsubi[2] & ( (1 << 15) - 1) ) << 16) | (long)xsubi[1]; +} + +double drand48(void) { + return erand48(_mingw_rand_state); +} + +double erand48(unsigned short xsubi[3]) { + return (double)nrand48(xsubi) / (1 << 31); +} + + +long int mrand48(void) { + return jrand48(_mingw_rand_state); +} + +long int jrand48(unsigned short xsubi[3]) { + _mingw_rand_next_state(xsubi); + return ((long)xsubi[2] << 16) | (long)xsubi[1]; +} + +void srand48(long int seedval) { + _mingw_rand_state[0] = 0x330E; + _mingw_rand_state[1] = seedval & ( (1 << 16) - 1); + _mingw_rand_state[2] = seedval >> 16; + _mingw_rand_state[3] = 0xE66D; + _mingw_rand_state[4] = 0xDEEC; + _mingw_rand_state[5] = 0x0005; + _mingw_rand_state[6] = 0x000B; +} + +unsigned short *seed48(unsigned short seed16v[3]) { + _mingw_rand_state[7] = _mingw_rand_state[0]; + _mingw_rand_state[8] = _mingw_rand_state[1]; + _mingw_rand_state[9] = _mingw_rand_state[2]; + _mingw_rand_state[0] = seed16v[0]; + _mingw_rand_state[1] = seed16v[1]; + _mingw_rand_state[2] = seed16v[2]; + return _mingw_rand_state + 7; +} + +void lcong48(unsigned short param[7]) { + _mingw_rand_state[0] = param[0]; + _mingw_rand_state[1] = param[1]; + _mingw_rand_state[2] = param[2]; + _mingw_rand_state[3] = param[3]; + _mingw_rand_state[4] = param[4]; + _mingw_rand_state[5] = param[5]; + _mingw_rand_state[6] = param[6]; +} + + +#endif