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