lemon/bits/mingw32_rand.cc
changeset 2035 e92071fadd3f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/mingw32_rand.cc	Mon Apr 03 19:47:37 2006 +0000
     1.3 @@ -0,0 +1,83 @@
     1.4 +#ifdef WIN32
     1.5 +
     1.6 +#include <lemon/bits/mingw32_rand.h>
     1.7 +
     1.8 +
     1.9 +static unsigned short _mingw_rand_state[10];
    1.10 +
    1.11 +void _mingw_rand_next_state(unsigned short xsubi[3]) {
    1.12 +  _mingw_rand_state[8] = _mingw_rand_state[9] = 0;
    1.13 +  _mingw_rand_state[7] =  _mingw_rand_state[6];
    1.14 +  for (int i = 0; i < 3; ++i) {
    1.15 +    unsigned long val = 0;
    1.16 +    for (int j = 0; i + j < 3; ++j) {
    1.17 +      val += (unsigned long)_mingw_rand_state[7 + i + j]
    1.18 +        + (unsigned long)xsubi[i] * (unsigned long)_mingw_rand_state[3 + j];
    1.19 +      _mingw_rand_state[7 + i + j] = val;
    1.20 +      val >>= 16;
    1.21 +    }
    1.22 +  }
    1.23 +  xsubi[0] = _mingw_rand_state[6];
    1.24 +  xsubi[1] = _mingw_rand_state[7];
    1.25 +  xsubi[2] = _mingw_rand_state[8];
    1.26 +}
    1.27 +
    1.28 +long int lrand48(void) {
    1.29 +  return nrand48(_mingw_rand_state);
    1.30 +}
    1.31 +
    1.32 +long int nrand48(unsigned short xsubi[3]) {
    1.33 +  _mingw_rand_next_state(xsubi);
    1.34 +  return ((long)(xsubi[2] & ( (1 << 15) - 1) ) << 16) | (long)xsubi[1];
    1.35 +}
    1.36 +
    1.37 +double drand48(void) {
    1.38 +  return erand48(_mingw_rand_state);
    1.39 +}
    1.40 +
    1.41 +double erand48(unsigned short xsubi[3]) {
    1.42 +  return (double)nrand48(xsubi) / (1 << 31);
    1.43 +}
    1.44 +
    1.45 +
    1.46 +long int mrand48(void) {
    1.47 +  return jrand48(_mingw_rand_state);
    1.48 +}
    1.49 +
    1.50 +long int jrand48(unsigned short xsubi[3]) {
    1.51 +  _mingw_rand_next_state(xsubi);
    1.52 +  return ((long)xsubi[2] << 16) | (long)xsubi[1];
    1.53 +}
    1.54 +
    1.55 +void srand48(long int seedval) {
    1.56 +  _mingw_rand_state[0] = 0x330E;
    1.57 +  _mingw_rand_state[1] = seedval & ( (1 << 16) - 1);
    1.58 +  _mingw_rand_state[2] = seedval >> 16;
    1.59 +  _mingw_rand_state[3] = 0xE66D;
    1.60 +  _mingw_rand_state[4] = 0xDEEC;
    1.61 +  _mingw_rand_state[5] = 0x0005;
    1.62 +  _mingw_rand_state[6] = 0x000B;
    1.63 +}
    1.64 +
    1.65 +unsigned short *seed48(unsigned short seed16v[3]) {
    1.66 +  _mingw_rand_state[7] = _mingw_rand_state[0];
    1.67 +  _mingw_rand_state[8] = _mingw_rand_state[1];
    1.68 +  _mingw_rand_state[9] = _mingw_rand_state[2];
    1.69 +  _mingw_rand_state[0] = seed16v[0];
    1.70 +  _mingw_rand_state[1] = seed16v[1];
    1.71 +  _mingw_rand_state[2] = seed16v[2];
    1.72 +  return _mingw_rand_state + 7;
    1.73 +}
    1.74 +
    1.75 +void lcong48(unsigned short param[7]) {
    1.76 +  _mingw_rand_state[0] = param[0];
    1.77 +  _mingw_rand_state[1] = param[1];
    1.78 +  _mingw_rand_state[2] = param[2];
    1.79 +  _mingw_rand_state[3] = param[3];
    1.80 +  _mingw_rand_state[4] = param[4];
    1.81 +  _mingw_rand_state[5] = param[5];
    1.82 +  _mingw_rand_state[6] = param[6];
    1.83 +}
    1.84 +
    1.85 +
    1.86 +#endif