author | peter1138 |
Tue, 22 Jan 2008 07:27:06 +0000 | |
changeset 8374 | 7a1b6c89cb89 |
parent 8142 | 837f47089a7c |
child 8434 | 558c39956ba2 |
permissions | -rw-r--r-- |
7935
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
1 |
/* $Id$ */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
2 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
3 |
/** @file random_func.cpp */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
4 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
5 |
#include "../stdafx.h" |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
6 |
#include "random_func.hpp" |
8113
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
8079
diff
changeset
|
7 |
#include "bitmath_func.hpp" |
7935
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
8 |
|
8142
837f47089a7c
(svn r11704) -Codechange: remove another bunch of useless includes.
rubidium
parents:
8113
diff
changeset
|
9 |
uint32 _random_seeds[2][2]; |
837f47089a7c
(svn r11704) -Codechange: remove another bunch of useless includes.
rubidium
parents:
8113
diff
changeset
|
10 |
|
7935
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
11 |
uint32 InteractiveRandom() |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
12 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
13 |
const uint32 s = _random_seeds[1][0]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
14 |
const uint32 t = _random_seeds[1][1]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
15 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
16 |
_random_seeds[1][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
17 |
return _random_seeds[1][1] = ROR(s, 3) - 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
18 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
19 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
20 |
uint InteractiveRandomRange(uint max) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
21 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
22 |
return GB(InteractiveRandom(), 0, 16) * max >> 16; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
23 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
24 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
25 |
#ifdef MERSENNE_TWISTER |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
26 |
// Source code for Mersenne Twister. |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
27 |
// A Random number generator with much higher quality random numbers. |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
28 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
29 |
#define N (624) // length of _mt_state vector |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
30 |
#define M (397) // a period parameter |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
31 |
#define K (0x9908B0DFU) // a magic constant |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
32 |
#define hiBit(u) ((u) & 0x80000000U) // mask all but highest bit of u |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
33 |
#define loBit(u) ((u) & 0x00000001U) // mask all but lowest bit of u |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
34 |
#define loBits(u) ((u) & 0x7FFFFFFFU) // mask the highest bit of u |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
35 |
#define mixBits(u, v) (hiBit(u)|loBits(v)) // move hi bit of u to hi bit of v |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
36 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
37 |
static uint32 _mt_state[N+1]; // _mt_state vector + 1 extra to not violate ANSI C |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
38 |
static uint32 *_mt_next; // _mt_next random value is computed from here |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
39 |
static int _mt_left = -1; // can *_mt_next++ this many times before reloading |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
40 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
41 |
void SetRandomSeed(register uint32 seed) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
42 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
43 |
register uint32 *s = _mt_state; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
44 |
_mt_left = 0; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
45 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
46 |
seed |= 1U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
47 |
seed &= 0xFFFFFFFFU; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
48 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
49 |
*s = seed; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
50 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
51 |
for (register uint i = N; i != 0; i--) { |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
52 |
seed *= 69069U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
53 |
*s++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
54 |
*s = seed & 0xFFFFFFFFU; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
55 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
56 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
57 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
58 |
static uint32 ReloadRandom() |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
59 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
60 |
if (_mt_left < -1) SetRandomSeed(4357U); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
61 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
62 |
_mt_left = N - 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
63 |
_mt_next = _mt_state + 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
64 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
65 |
register uint32 *p0 = _mt_state; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
66 |
register uint32 *p2 = _mt_state + 2; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
67 |
register uint32 *pM = _mt_state + M; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
68 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
69 |
register uint32 s0 = _mt_state[0]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
70 |
register uint32 s1 = _mt_state[1]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
71 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
72 |
register uint i = 0; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
73 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
74 |
for (i = (N - M + 1); i != 0; i--) { |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
75 |
s0 = s1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
76 |
s1 = *p2; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
77 |
*p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
78 |
*p0++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
79 |
*p2++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
80 |
*pM++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
81 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
82 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
83 |
pM = _mt_state; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
84 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
85 |
for (i = M; i != 0; i--) { |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
86 |
s0 = s1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
87 |
s1 = *p2; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
88 |
*p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
89 |
*p0++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
90 |
*p2++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
91 |
*pM++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
92 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
93 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
94 |
s1 = _mt_state[0]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
95 |
*p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
96 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
97 |
s1 ^= (s1 >> 11); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
98 |
s1 ^= (s1 << 7) & 0x9D2C5680U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
99 |
s1 ^= (s1 << 15) & 0xEFC60000U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
100 |
s1 ^= (s1 >> 18); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
101 |
return s1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
102 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
103 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
104 |
uint32 Random() |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
105 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
106 |
_mt_left--; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
107 |
if (_mt_left < 0) return ReloadRandom(); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
108 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
109 |
uint32 y = *_mt_next; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
110 |
*_mt_next++; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
111 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
112 |
y ^= (y >> 11); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
113 |
y ^= (y << 7) & 0x9D2C5680U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
114 |
y ^= (y << 15) & 0xEFC60000U; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
115 |
y ^= (y >> 18); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
116 |
return y; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
117 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
118 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
119 |
#else /* MERSENNE_TWISTER */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
120 |
void SetRandomSeed(uint32 seed) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
121 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
122 |
_random_seeds[0][0] = seed; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
123 |
_random_seeds[0][1] = seed; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
124 |
_random_seeds[1][0] = seed * 0x1234567; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
125 |
_random_seeds[1][1] = _random_seeds[1][0]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
126 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
127 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
128 |
#ifdef RANDOM_DEBUG |
8079
8ed263cb705a
(svn r11640) -Fix: missed change of include when moving stuff to random_func.cpp
rubidium
parents:
7936
diff
changeset
|
129 |
#include "../network/network_data.h" |
7935
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
130 |
uint32 DoRandom(int line, const char *file) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
131 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
132 |
if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server)) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
133 |
printf("Random [%d/%d] %s:%d\n",_frame_counter, (byte)_current_player, file, line); |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
134 |
#else /* RANDOM_DEBUG */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
135 |
uint32 Random() |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
136 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
137 |
#endif /* RANDOM_DEBUG */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
138 |
const uint32 s = _random_seeds[0][0]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
139 |
const uint32 t = _random_seeds[0][1]; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
140 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
141 |
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
142 |
return _random_seeds[0][1] = ROR(s, 3) - 1; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
143 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
144 |
#endif /* MERSENNE_TWISTER */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
145 |
|
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
146 |
#if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
147 |
uint DoRandomRange(uint max, int line, const char *file) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
148 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
149 |
return GB(DoRandom(line, file), 0, 16) * max >> 16; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
150 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
151 |
#else /* RANDOM_DEBUG & !MERSENNE_TWISTER */ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
152 |
uint RandomRange(uint max) |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
153 |
{ |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
154 |
return GB(Random(), 0, 16) * max >> 16; |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
155 |
} |
c2d1b2f4ecd6
(svn r11488) -Codechange: Spilt the random functions out to seperate file
skidd13
parents:
diff
changeset
|
156 |
#endif /* RANDOM_DEBUG & !MERSENNE_TWISTER */ |