mt.c File Reference

#include <math.h>
#include "machine.h"
#include "grand.h"
#include "sciprint.h"

Include dependency graph for mt.c:

Go to the source code of this file.

Defines

#define N   624
#define M   397
#define MATRIX_A   0x9908b0df
#define UPPER_MASK   0x80000000
#define LOWER_MASK   0x7fffffff
#define TEMPERING_MASK_B   0x9d2c5680
#define TEMPERING_MASK_C   0xefc60000
#define TEMPERING_SHIFT_U(y)   (y >> 11)
#define TEMPERING_SHIFT_S(y)   (y << 7)
#define TEMPERING_SHIFT_T(y)   (y << 15)
#define TEMPERING_SHIFT_L(y)   (y >> 18)

Functions

int set_state_mt_simple (double s)
void sciprint __PARAMS ((char *fmt,...))
unsigned long randmt ()
int set_state_mt (double seed_array[])
void get_state_mt (double state[])

Variables

static unsigned long mt [N]
static int mti = N
static int is_init = 0
static double DEFAULT_SEED = 5489.0


Define Documentation

#define LOWER_MASK   0x7fffffff

Definition at line 66 of file mt.c.

Referenced by randmt().

#define M   397

Definition at line 63 of file mt.c.

#define MATRIX_A   0x9908b0df

Definition at line 64 of file mt.c.

Referenced by randmt().

#define N   624

Definition at line 62 of file mt.c.

#define TEMPERING_MASK_B   0x9d2c5680

Definition at line 69 of file mt.c.

Referenced by randmt().

#define TEMPERING_MASK_C   0xefc60000

Definition at line 70 of file mt.c.

Referenced by randmt().

#define TEMPERING_SHIFT_L ( y   )     (y >> 18)

Definition at line 74 of file mt.c.

Referenced by randmt().

#define TEMPERING_SHIFT_S ( y   )     (y << 7)

Definition at line 72 of file mt.c.

Referenced by randmt().

#define TEMPERING_SHIFT_T ( y   )     (y << 15)

Definition at line 73 of file mt.c.

Referenced by randmt().

#define TEMPERING_SHIFT_U ( y   )     (y >> 11)

Definition at line 71 of file mt.c.

Referenced by randmt().

#define UPPER_MASK   0x80000000

Definition at line 65 of file mt.c.

Referenced by randmt().


Function Documentation

void sciprint __PARAMS ( (char *fmt,...)   ) 

void get_state_mt ( double  state[]  ) 

Definition at line 181 of file mt.c.

References DEFAULT_SEED, i, is_init, mt, mti, N, and set_state_mt_simple().

Referenced by RandI().

00182 {
00183     int i;
00184 
00185     if ( ! is_init )
00186       set_state_mt_simple(DEFAULT_SEED);
00187     
00188     state[0] = (double) mti;
00189     for (i=0;i<N;i++) 
00190       state[i+1] = (double) mt[i];
00191 }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long randmt (  ) 

Definition at line 83 of file mt.c.

References DEFAULT_SEED, is_init, LOWER_MASK, M, MATRIX_A, mt, mti, N, set_state_mt_simple(), TEMPERING_MASK_B, TEMPERING_MASK_C, TEMPERING_SHIFT_L, TEMPERING_SHIFT_S, TEMPERING_SHIFT_T, TEMPERING_SHIFT_U, UPPER_MASK, and y.

00084 {
00085     unsigned long y;
00086     static unsigned long mag01[2]={0x0, MATRIX_A};
00087     /* mag01[x] = x * MATRIX_A  for x=0,1 */
00088 
00089     if (mti >= N) { /* generate N words at one time */
00090         int kk;
00091 
00092         if ( ! is_init )
00093           set_state_mt_simple(DEFAULT_SEED);
00094 
00095         for (kk=0;kk<N-M;kk++) {
00096             y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
00097             mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
00098         }
00099         for (;kk<N-1;kk++) {
00100             y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
00101             mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
00102         }
00103         y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
00104         mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
00105 
00106         mti = 0;
00107     }
00108   
00109     y = mt[mti++];
00110     y ^= TEMPERING_SHIFT_U(y);
00111     y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
00112     y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
00113     y ^= TEMPERING_SHIFT_L(y);
00114 
00115     return ( y );
00116 }

Here is the call graph for this function:

int set_state_mt ( double  seed_array[]  ) 

Definition at line 161 of file mt.c.

References i, int, is_init, mt, mti, N, and sciprint().

Referenced by RandI().

00163 {
00164     int i, mti_try;
00165 
00166     mti_try = (int) seed_array[0];
00167     if (mti_try < 1  ||  mti_try > 624)
00168       {
00169         sciprint("\n\r the first component of the mt state mt, must be an integer in [1, 624] \n\r");
00170         return ( 0 );
00171       }
00172     is_init = 1;
00173     mti = mti_try;
00174     for (i=0;i<N;i++) 
00175       mt[i] = ((unsigned long) seed_array[i+1]) & 0xffffffff;
00176     return ( 1 );
00177 }

Here is the call graph for this function:

Here is the caller graph for this function:

int set_state_mt_simple ( double  s  ) 


Variable Documentation

double DEFAULT_SEED = 5489.0 [static]

Definition at line 79 of file mt.c.

Referenced by get_state_mt(), and randmt().

int is_init = 0 [static]

Definition at line 78 of file mt.c.

unsigned long mt[N] [static]

Definition at line 76 of file mt.c.

Referenced by get_state_mt(), intbsplin3val(), inteval_cshep2d(), intinterp1(), intinterp3d(), my_ode_job(), putentries(), randmt(), set_state_mt(), and set_state_mt_simple().

int mti = N [static]

Definition at line 77 of file mt.c.

Referenced by get_state_mt(), randmt(), set_state_mt(), and set_state_mt_simple().


Generated on Sun Mar 4 16:11:28 2007 for Scilab [trunk] by  doxygen 1.5.1