Changeset 481

Show
Ignore:
Timestamp:
09/26/07 03:57:40 (14 months ago)
Author:
krobillard
Message:

mt19937ar.c now uses uint32_t rather than unsigned long.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/support/mt19937ar.c

    r248 r481  
    4040   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 
    4141   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 
     42 
     43 
     44   Modified by Karl Robillard to use uint32_t 
    4245*/ 
    4346 
     47#include <stdint.h> 
    4448#include <stdio.h> 
    4549 
     
    5155#define LOWER_MASK 0x7fffffffUL /* least significant r bits */ 
    5256 
    53 static unsigned long mt[N]; /* the array for the state vector  */ 
    54 static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 
     57static uint32_t mt[N]; /* the array for the state vector  */ 
     58static int32_t mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 
    5559 
    5660/* initializes mt[N] with a seed */ 
    57 void init_genrand(unsigned long s) 
     61void init_genrand(uint32_t s) 
    5862{ 
    5963    mt[0]= s & 0xffffffffUL; 
     
    6569        /* only MSBs of the array mt[].                        */ 
    6670        /* 2002/01/09 modified by Makoto Matsumoto             */ 
     71#if 0 
    6772        mt[mti] &= 0xffffffffUL; 
    6873        /* for >32 bit machines */ 
    69     } 
    70 } 
    71  
    72 #if 0 
     74#endif 
     75    } 
     76} 
     77 
     78#ifdef UNIT_TEST 
    7379/* initialize by an array with array-length */ 
    7480/* init_key is the array for initializing keys */ 
    7581/* key_length is its length */ 
    7682/* slight change for C++, 2004/2/26 */ 
    77 void init_by_array(unsigned long init_key[], int key_length) 
     83void init_by_array(uint32_t init_key[], int key_length) 
    7884{ 
    7985    int i, j, k; 
     
    102108 
    103109/* generates a random number on [0,0xffffffff]-interval */ 
    104 unsigned long genrand_int32(void) 
    105 { 
    106     unsigned long y; 
    107     static unsigned long mag01[2]={0x0UL, MATRIX_A}; 
     110uint32_t genrand_int32(void) 
     111{ 
     112    uint32_t y; 
     113    static uint32_t mag01[2]={0x0UL, MATRIX_A}; 
    108114    /* mag01[x] = x * MATRIX_A  for x=0,1 */ 
    109115 
     
    141147#if 0 
    142148/* generates a random number on [0,0x7fffffff]-interval */ 
    143 long genrand_int31(void) 
    144 { 
    145     return (long)(genrand_int32()>>1); 
     149int32_t genrand_int31(void) 
     150{ 
     151    return (int32_t)(genrand_int32()>>1); 
    146152} 
    147153 
     
    161167} 
    162168 
    163 #if 0 
     169#ifdef UNIT_TEST 
    164170/* generates a random number on (0,1)-real-interval */ 
    165171double genrand_real3(void) 
     
    172178double genrand_res53(void)  
    173179{  
    174     unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;  
     180    uint32_t a=genrand_int32()>>5, b=genrand_int32()>>6;  
    175181    return(a*67108864.0+b)*(1.0/9007199254740992.0);  
    176182}  
     
    180186{ 
    181187    int i; 
    182     unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4; 
     188    uint32_t init[4]={0x123, 0x234, 0x345, 0x456}, length=4; 
    183189    init_by_array(init, length); 
    184190    printf("1000 outputs of genrand_int32()\n");