Changeset 481
- Timestamp:
- 09/26/07 03:57:40 (14 months ago)
- Files:
-
- 1 modified
-
trunk/thune/support/mt19937ar.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/support/mt19937ar.c
r248 r481 40 40 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 41 41 email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 42 43 44 Modified by Karl Robillard to use uint32_t 42 45 */ 43 46 47 #include <stdint.h> 44 48 #include <stdio.h> 45 49 … … 51 55 #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ 52 56 53 static u nsigned longmt[N]; /* the array for the state vector */54 static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */57 static uint32_t mt[N]; /* the array for the state vector */ 58 static int32_t mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 55 59 56 60 /* initializes mt[N] with a seed */ 57 void init_genrand(u nsigned longs)61 void init_genrand(uint32_t s) 58 62 { 59 63 mt[0]= s & 0xffffffffUL; … … 65 69 /* only MSBs of the array mt[]. */ 66 70 /* 2002/01/09 modified by Makoto Matsumoto */ 71 #if 0 67 72 mt[mti] &= 0xffffffffUL; 68 73 /* for >32 bit machines */ 69 } 70 } 71 72 #if 0 74 #endif 75 } 76 } 77 78 #ifdef UNIT_TEST 73 79 /* initialize by an array with array-length */ 74 80 /* init_key is the array for initializing keys */ 75 81 /* key_length is its length */ 76 82 /* slight change for C++, 2004/2/26 */ 77 void init_by_array(u nsigned longinit_key[], int key_length)83 void init_by_array(uint32_t init_key[], int key_length) 78 84 { 79 85 int i, j, k; … … 102 108 103 109 /* generates a random number on [0,0xffffffff]-interval */ 104 u nsigned longgenrand_int32(void)105 { 106 u nsigned longy;107 static u nsigned longmag01[2]={0x0UL, MATRIX_A};110 uint32_t genrand_int32(void) 111 { 112 uint32_t y; 113 static uint32_t mag01[2]={0x0UL, MATRIX_A}; 108 114 /* mag01[x] = x * MATRIX_A for x=0,1 */ 109 115 … … 141 147 #if 0 142 148 /* generates a random number on [0,0x7fffffff]-interval */ 143 longgenrand_int31(void)144 { 145 return ( long)(genrand_int32()>>1);149 int32_t genrand_int31(void) 150 { 151 return (int32_t)(genrand_int32()>>1); 146 152 } 147 153 … … 161 167 } 162 168 163 #if 0169 #ifdef UNIT_TEST 164 170 /* generates a random number on (0,1)-real-interval */ 165 171 double genrand_real3(void) … … 172 178 double genrand_res53(void) 173 179 { 174 u nsigned longa=genrand_int32()>>5, b=genrand_int32()>>6;180 uint32_t a=genrand_int32()>>5, b=genrand_int32()>>6; 175 181 return(a*67108864.0+b)*(1.0/9007199254740992.0); 176 182 } … … 180 186 { 181 187 int i; 182 u nsigned longinit[4]={0x123, 0x234, 0x345, 0x456}, length=4;188 uint32_t init[4]={0x123, 0x234, 0x345, 0x456}, length=4; 183 189 init_by_array(init, length); 184 190 printf("1000 outputs of genrand_int32()\n");
