Version: 8.3.0
mt19937ar.cxx File Reference
#include <stdio.h>
Include dependency graph for mt19937ar.cxx:

Go to the source code of this file.

Macros

#define N   624
 
#define M   397
 
#define MATRIX_A   0x9908b0dfUL /* constant vector a */
 
#define UPPER_MASK   0x80000000UL /* most significant w-r bits */
 
#define LOWER_MASK   0x7fffffffUL /* least significant r bits */
 

Functions

void init_genrand (unsigned long s)
 
void init_by_array (unsigned long init_key[], int key_length)
 
unsigned long genrand_int32 (void)
 
long genrand_int31 (void)
 
double genrand_real1 (void)
 
double genrand_real2 (void)
 
double genrand_real3 (void)
 
double genrand_res53 (void)
 

Variables

static unsigned long mt [N]
 
static int mti =N+1
 

Macro Definition Documentation

#define LOWER_MASK   0x7fffffffUL /* least significant r bits */

Definition at line 27 of file mt19937ar.cxx.

Referenced by genrand_int32().

#define M   397

Definition at line 24 of file mt19937ar.cxx.

Referenced by genrand_int32().

#define MATRIX_A   0x9908b0dfUL /* constant vector a */

Definition at line 25 of file mt19937ar.cxx.

Referenced by genrand_int32().

#define N   624

Definition at line 23 of file mt19937ar.cxx.

Referenced by genrand_int32(), init_by_array(), and init_genrand().

#define UPPER_MASK   0x80000000UL /* most significant w-r bits */

Definition at line 26 of file mt19937ar.cxx.

Referenced by genrand_int32().

Function Documentation

long genrand_int31 ( void  )

Definition at line 116 of file mt19937ar.cxx.

References genrand_int32().

117 {
118  return (long)(genrand_int32()>>1);
119 }
unsigned long genrand_int32 ( void  )

Definition at line 78 of file mt19937ar.cxx.

References init_genrand(), LOWER_MASK, M, MATRIX_A, mt, mti, N, and UPPER_MASK.

Referenced by genrand_int31(), genrand_real1(), genrand_real2(), genrand_real3(), and genrand_res53().

79 {
80  unsigned long y;
81  static unsigned long mag01[2]={0x0UL, MATRIX_A};
82  /* mag01[x] = x * MATRIX_A for x=0,1 */
83 
84  if (mti >= N) { /* generate N words at one time */
85  int kk;
86 
87  if (mti == N+1) /* if init_genrand() has not been called, */
88  init_genrand(5489UL); /* a default initial seed is used */
89 
90  for (kk=0;kk<N-M;kk++) {
91  y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
92  mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
93  }
94  for (;kk<N-1;kk++) {
95  y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
96  mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
97  }
98  y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
99  mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
100 
101  mti = 0;
102  }
103 
104  y = mt[mti++];
105 
106  /* Tempering */
107  y ^= (y >> 11);
108  y ^= (y << 7) & 0x9d2c5680UL;
109  y ^= (y << 15) & 0xefc60000UL;
110  y ^= (y >> 18);
111 
112  return y;
113 }
double genrand_real1 ( void  )

Definition at line 122 of file mt19937ar.cxx.

References genrand_int32().

Referenced by Sphere::fill(), and Cube::tire().

123 {
124  return genrand_int32()*(1.0/4294967295.0);
125  /* divided by 2^32-1 */
126 }
double genrand_real2 ( void  )

Definition at line 129 of file mt19937ar.cxx.

References genrand_int32().

130 {
131  return genrand_int32()*(1.0/4294967296.0);
132  /* divided by 2^32 */
133 }
double genrand_real3 ( void  )

Definition at line 136 of file mt19937ar.cxx.

References genrand_int32().

Referenced by randGauss().

137 {
138  return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
139  /* divided by 2^32 */
140 }
double genrand_res53 ( void  )

Definition at line 143 of file mt19937ar.cxx.

References gui.CONNECTOR::a, gui.CONNECTOR::b, and genrand_int32().

144 {
145  unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
146  return(a*67108864.0+b)*(1.0/9007199254740992.0);
147 }
void init_by_array ( unsigned long  init_key[],
int  key_length 
)

Definition at line 52 of file mt19937ar.cxx.

References CORBAEngineTest::i, init_genrand(), mt, and N.

Referenced by initrand().

53 {
54  int i, j, k;
55  init_genrand(19650218UL);
56  i=1; j=0;
57  k = (N>key_length ? N : key_length);
58  for (; k; k--) {
59  mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
60  + init_key[j] + j; /* non linear */
61  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
62  i++; j++;
63  if (i>=N) { mt[0] = mt[N-1]; i=1; }
64  if (j>=key_length) j=0;
65  }
66  for (k=N-1; k; k--) {
67  mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
68  - i; /* non linear */
69  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
70  i++;
71  if (i>=N) { mt[0] = mt[N-1]; i=1; }
72  }
73 
74  mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
75 }
void init_genrand ( unsigned long  s)

Definition at line 33 of file mt19937ar.cxx.

References mt, mti, and N.

Referenced by genrand_int32(), and init_by_array().

34 {
35  mt[0]= s & 0xffffffffUL;
36  for (mti=1; mti<N; mti++) {
37  mt[mti] =
38  (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
39  /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
40  /* In the previous versions, MSBs of the seed affect */
41  /* only MSBs of the array mt[]. */
42  /* 2002/01/09 modified by Makoto Matsumoto */
43  mt[mti] &= 0xffffffffUL;
44  /* for >32 bit machines */
45  }
46 }

Variable Documentation

unsigned long mt[N]
static

Definition at line 29 of file mt19937ar.cxx.

Referenced by genrand_int32(), init_by_array(), and init_genrand().

int mti =N+1
static

Definition at line 30 of file mt19937ar.cxx.

Referenced by genrand_int32(), and init_genrand().