Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VSRandom Class Reference

#include <vs_random.h>

Public Member Functions

 VSRandom (unsigned int s)
 
void init_genrand (unsigned int s)
 
 VSRandom (unsigned int init_key[], unsigned int key_length)
 
unsigned int genrand_int32 (void)
 
int genrand_int31 (void)
 
unsigned int rand ()
 
double genrand_real1 (void)
 
double genrand_real2 (void)
 
double uniformInc (double min, double max)
 
double uniformExc (double min, double max)
 
double genrand_real3 (void)
 
double genrand_res53 (void)
 

Detailed Description

Definition at line 45 of file vs_random.h.

Constructor & Destructor Documentation

VSRandom::VSRandom ( unsigned int  s)
inline

Definition at line 72 of file vs_random.h.

References init_genrand().

72  : VSRandom( unsigned int s ) : mti( N()+1 )
73  {
74  init_genrand( s );
75  }
VSRandom::VSRandom ( unsigned int  init_key[],
unsigned int  key_length 
)
inline

Definition at line 97 of file vs_random.h.

References i, init_genrand(), j, and k.

97  : mti( N()+1 )
98  {
99  unsigned int i, j, k;
100  init_genrand( 19650218UL );
101  i = 1;
102  j = 0;
103  k = (N() > key_length ? N() : key_length);
104  for (; k; k--) {
105  mt[i] = ( mt[i]^( ( mt[i-1]^(mt[i-1]>>30) )*1664525UL ) )
106  +init_key[j]+j; /* non linear */
107  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
108  i++;
109  j++;
110  if ( i >= N() ) {
111  mt[0] = mt[N()-1];
112  i = 1;
113  }
114  if (j >= key_length) j = 0;
115  }
116  for (k = N()-1; k; k--) {
117  mt[i] = ( mt[i]^( ( mt[i-1]^(mt[i-1]>>30) )*1566083941UL ) )
118  -i; /* non linear */
119  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
120  i++;
121  if ( i >= N() ) {
122  mt[0] = mt[N()-1];
123  i = 1;
124  }
125  }
126  mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
127  }

Member Function Documentation

int VSRandom::genrand_int31 ( void  )
inline

Definition at line 160 of file vs_random.h.

References genrand_int32().

Referenced by ZoneMgr::broadcastDamage(), ZoneMgr::broadcastSnapshots(), ChooseNavPoint(), rand(), Unit::Repair(), and Orders::FireAt::ShouldFire().

161  {
162  return (int) (genrand_int32()>>1);
163  }
unsigned int VSRandom::genrand_int32 ( void  )
inline

Definition at line 129 of file vs_random.h.

References init_genrand(), and y.

Referenced by StarSystem::AddUnit(), commandI::dummy(), genrand_int31(), genrand_real1(), genrand_real2(), genrand_real3(), genrand_res53(), AnimatedTexture::LoadAni(), and StarSystem::UpdateUnitPhysics().

130  {
131  unsigned int y;
132  static unsigned int mag01[2] = {0x0UL, MATRIX_A()};
133  /* mag01[x] = x * MATRIX_A for x=0,1 */
134  if ( mti >= N() ) {
135  /* generate N words at one time */
136  unsigned int kk;
137  if (mti == N()+1) /* if init_genrand() has not been called, */
138  init_genrand( 5489UL ); /* a default initial seed is used */
139  for (kk = 0; kk < N()-M(); kk++) {
140  y = ( mt[kk]&UPPER_MASK() )|( mt[kk+1]&LOWER_MASK() );
141  mt[kk] = mt[kk+M()]^(y>>1)^mag01[y&0x1UL];
142  }
143  for (; kk < N()-1; kk++) {
144  y = ( mt[kk]&UPPER_MASK() )|( mt[kk+1]&LOWER_MASK() );
145  mt[kk] = mt[kk+( M()-N() )]^(y>>1)^mag01[y&0x1UL];
146  }
147  y = ( mt[N()-1]&UPPER_MASK() )|( mt[0]&LOWER_MASK() );
148  mt[N()-1] = mt[M()-1]^(y>>1)^mag01[y&0x1UL];
149  mti = 0;
150  }
151  y = mt[mti++];
152  /* Tempering */
153  y ^= (y>>11);
154  y ^= (y<<7)&0x9d2c5680UL;
155  y ^= (y<<15)&0xefc60000UL;
156  y ^= (y>>18);
157  return y;
158  }
double VSRandom::genrand_real1 ( void  )
inline

Definition at line 169 of file vs_random.h.

References genrand_int32().

Referenced by uniformInc().

170  {
171  return genrand_int32()*(1.0/4294967295.0);
172  /* divided by 2^32-1 */
173  }
double VSRandom::genrand_real2 ( void  )
inline

Definition at line 175 of file vs_random.h.

References genrand_int32().

Referenced by uniformExc().

176  {
177  return genrand_int32()*(1.0/4294967296.0);
178  /* divided by 2^32 */
179  }
double VSRandom::genrand_real3 ( void  )
inline

Definition at line 190 of file vs_random.h.

References genrand_int32().

191  {
192  return ( ( (double) genrand_int32() )+0.5 )*(1.0/4294967296.0);
193  /* divided by 2^32 */
194  }
double VSRandom::genrand_res53 ( void  )
inline

Definition at line 196 of file vs_random.h.

References a, b, and genrand_int32().

197  {
198  unsigned int a = genrand_int32()>>5, b = genrand_int32()>>6;
199  return (a*67108864.0+b)*(1.0/9007199254740992.0);
200  }
void VSRandom::init_genrand ( unsigned int  s)
inline

Definition at line 76 of file vs_random.h.

Referenced by genrand_int32(), Orders::FireAt::ShouldFire(), and VSRandom().

77  {
78  mt[0] = s&0xffffffffUL;
79  for (mti = 1; mti < N(); mti++) {
80  mt[mti] =
81  (1812433253UL*( mt[mti-1]^(mt[mti-1]>>30) )+mti);
82  /*
83  * See Knuth TAOCP Vol2. 3 rd Ed. P.106 for multiplier.
84  * In the previous versions, MSB s of the seed affect
85  * only MSBs of the array mt[].
86  * 2002/01/09 modified by Makoto Matsumoto
87  */
88  mt[mti] &= 0xffffffffUL;
89  /* for >32 bit machines */
90  }
91  }
unsigned int VSRandom::rand ( )
inline
double VSRandom::uniformExc ( double  min,
double  max 
)
inline

Definition at line 184 of file vs_random.h.

References genrand_real2(), and min().

Referenced by ChooseNavPoint(), and createObjects().

185  {
186  return genrand_real2()*(max-min)+min;
187  }

The documentation for this class was generated from the following file: