31 static const unsigned SIZE = 624;
32 static const unsigned PERIOD = 397;
33 static const unsigned DIFF = SIZE - PERIOD;
35 static uint32_t MT[SIZE];
36 static unsigned index = 0;
38 #define M32(x) (0x80000000 & (x)) // 32nd Most Significant Bit 39 #define L31(x) (0x7FFFFFFF & (x)) // 31 Least Significant Bits 40 #define ODD(x) ((x) & 1) // Check if number is odd 42 #define UNROLL(expr) \ 43 y = M32(MT[i]) | L31(MT[i+1]); \ 44 MT[i] = MT[expr] ^ (y>>1) ^ MATRIX[ODD(y)]; \ 47 #define MD_UINT32_MAX std::numeric_limits<uint32_t>::max() 49 static inline void generate_numbers()
69 static const uint32_t MATRIX[2] = {0, 0x9908b0df};
73 while ( i < ( DIFF - 1 ) )
84 UNROLL( ( i + PERIOD ) % SIZE );
87 while ( i < ( SIZE - 1 ) )
107 y =
M32( MT[SIZE - 1] ) |
L31( MT[0] );
108 MT[SIZE - 1] = MT[PERIOD - 1] ^ ( y >> 1 ) ^ MATRIX[
ODD( y )];
111 extern "C" void seed( uint32_t value )
148 for (
unsigned i = 1; i < SIZE; ++i )
149 MT[i] = 0x6c078965 * ( MT[i - 1] ^ MT[i - 1] >> 30 ) + i;
157 uint32_t y = MT[index];
161 y ^= y << 7 & 0x9d2c5680;
162 y ^= y << 15 & 0xefc60000;
165 if ( ++index == SIZE )
188 return static_cast<int>( 0x7FFFFFFF &
rand_u32() );
193 seed( static_cast<uint32_t>( value ) );
void seed(uint32_t value)
void mt_srand(unsigned value)