|
1 #ifdef WIN32 |
|
2 |
|
3 #include <lemon/bits/mingw32_rand.h> |
|
4 |
|
5 |
|
6 static unsigned short _mingw_rand_state[10]; |
|
7 |
|
8 void _mingw_rand_next_state(unsigned short xsubi[3]) { |
|
9 _mingw_rand_state[8] = _mingw_rand_state[9] = 0; |
|
10 _mingw_rand_state[7] = _mingw_rand_state[6]; |
|
11 for (int i = 0; i < 3; ++i) { |
|
12 unsigned long val = 0; |
|
13 for (int j = 0; i + j < 3; ++j) { |
|
14 val += (unsigned long)_mingw_rand_state[7 + i + j] |
|
15 + (unsigned long)xsubi[i] * (unsigned long)_mingw_rand_state[3 + j]; |
|
16 _mingw_rand_state[7 + i + j] = val; |
|
17 val >>= 16; |
|
18 } |
|
19 } |
|
20 xsubi[0] = _mingw_rand_state[6]; |
|
21 xsubi[1] = _mingw_rand_state[7]; |
|
22 xsubi[2] = _mingw_rand_state[8]; |
|
23 } |
|
24 |
|
25 long int lrand48(void) { |
|
26 return nrand48(_mingw_rand_state); |
|
27 } |
|
28 |
|
29 long int nrand48(unsigned short xsubi[3]) { |
|
30 _mingw_rand_next_state(xsubi); |
|
31 return ((long)(xsubi[2] & ( (1 << 15) - 1) ) << 16) | (long)xsubi[1]; |
|
32 } |
|
33 |
|
34 double drand48(void) { |
|
35 return erand48(_mingw_rand_state); |
|
36 } |
|
37 |
|
38 double erand48(unsigned short xsubi[3]) { |
|
39 return (double)nrand48(xsubi) / (1 << 31); |
|
40 } |
|
41 |
|
42 |
|
43 long int mrand48(void) { |
|
44 return jrand48(_mingw_rand_state); |
|
45 } |
|
46 |
|
47 long int jrand48(unsigned short xsubi[3]) { |
|
48 _mingw_rand_next_state(xsubi); |
|
49 return ((long)xsubi[2] << 16) | (long)xsubi[1]; |
|
50 } |
|
51 |
|
52 void srand48(long int seedval) { |
|
53 _mingw_rand_state[0] = 0x330E; |
|
54 _mingw_rand_state[1] = seedval & ( (1 << 16) - 1); |
|
55 _mingw_rand_state[2] = seedval >> 16; |
|
56 _mingw_rand_state[3] = 0xE66D; |
|
57 _mingw_rand_state[4] = 0xDEEC; |
|
58 _mingw_rand_state[5] = 0x0005; |
|
59 _mingw_rand_state[6] = 0x000B; |
|
60 } |
|
61 |
|
62 unsigned short *seed48(unsigned short seed16v[3]) { |
|
63 _mingw_rand_state[7] = _mingw_rand_state[0]; |
|
64 _mingw_rand_state[8] = _mingw_rand_state[1]; |
|
65 _mingw_rand_state[9] = _mingw_rand_state[2]; |
|
66 _mingw_rand_state[0] = seed16v[0]; |
|
67 _mingw_rand_state[1] = seed16v[1]; |
|
68 _mingw_rand_state[2] = seed16v[2]; |
|
69 return _mingw_rand_state + 7; |
|
70 } |
|
71 |
|
72 void lcong48(unsigned short param[7]) { |
|
73 _mingw_rand_state[0] = param[0]; |
|
74 _mingw_rand_state[1] = param[1]; |
|
75 _mingw_rand_state[2] = param[2]; |
|
76 _mingw_rand_state[3] = param[3]; |
|
77 _mingw_rand_state[4] = param[4]; |
|
78 _mingw_rand_state[5] = param[5]; |
|
79 _mingw_rand_state[6] = param[6]; |
|
80 } |
|
81 |
|
82 |
|
83 #endif |