fsultra.c File Reference

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

Include dependency graph for fsultra.c:

Go to the source code of this file.

Defines

#define N   37
#define N2   24
#define SWB(c, x, y, z)   c = (y<0) ? (((z=x-y-c) < 0) || (x>=0)) : (((z=x-y-c) < 0) && (x>=0));

Functions

void sciprint __PARAMS ((char *fmt,...))
void advance_state_swb ()
int set_state_fsultra_simple (double s1, double s2)
int set_state_fsultra (double *s)
void get_state_fsultra (double s[])
unsigned long fsultra ()

Variables

static int is_init = 0
static long swb_state [N]
static int swb_index = N
static int swb_flag
static unsigned long cong_state
static double DEFAULT_SEED1 = 1234567.0
static double DEFAULT_SEED2 = 7654321.0


Define Documentation

#define N   37

Definition at line 66 of file fsultra.c.

Referenced by advance_state_swb(), C2F(), ChildrenCounter(), contourif(), creadbmat(), createvarfrom(), DrawMerge3d(), fsultra(), get_state_fsultra(), get_state_mt(), intdgeesx(), intdgesvd(), intdgetrf(), intdlassq(), intdsyev(), intreadxls(), intzgeesx(), Merge3dBuildTable(), Merge3dDimension(), mxCalloc(), mxgetscalar(), mxSetJc(), randmt(), set_state_fsultra(), set_state_fsultra_simple(), set_state_mt(), set_state_mt_simple(), set_surface_color_property(), set_tics_style_property(), set_xtics_coord_property(), and set_ytics_coord_property().

#define N2   24

Definition at line 67 of file fsultra.c.

Referenced by advance_state_swb().

#define SWB ( c,
x,
y,
z   )     c = (y<0) ? (((z=x-y-c) < 0) || (x>=0)) : (((z=x-y-c) < 0) && (x>=0));

Definition at line 103 of file fsultra.c.

Referenced by advance_state_swb().


Function Documentation

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

void advance_state_swb (  ) 

Definition at line 107 of file fsultra.c.

References i, N, N2, SWB, swb_flag, swb_index, and swb_state.

Referenced by fsultra(), and set_state_fsultra_simple().

00108 { 
00109   int i;
00110   /*
00111    *  The following are the heart of the system and should be
00112    *  written is assembler to be as fast as possible. It may even make sense
00113    *  to unravel the loop and simply wirte 37 consecutive SWB operations!
00114    */
00115   for (i=0;  i<N2; i++) 
00116     SWB(swb_flag,swb_state[i+N-N2],swb_state[i],swb_state[i]);
00117   for (i=N2; i<N;  i++) 
00118     SWB(swb_flag,swb_state[i  -N2],swb_state[i],swb_state[i]);
00119   swb_index = 0;
00120 }

Here is the caller graph for this function:

unsigned long fsultra (  ) 

Definition at line 225 of file fsultra.c.

References advance_state_swb(), cong_state, DEFAULT_SEED1, DEFAULT_SEED2, is_init, N, set_state_fsultra_simple(), swb_index, and swb_state.

00226 {
00227   if (swb_index >= N)  /* generate N words at one time */
00228     { 
00229       if ( ! is_init )
00230         set_state_fsultra_simple(DEFAULT_SEED1, DEFAULT_SEED2);
00231       else
00232         advance_state_swb();
00233     }
00234   return (swb_state[swb_index++] ^ (cong_state = cong_state * 69069));
00235 }

Here is the call graph for this function:

void get_state_fsultra ( double  s[]  ) 

Definition at line 211 of file fsultra.c.

References cong_state, DEFAULT_SEED1, DEFAULT_SEED2, i, is_init, N, set_state_fsultra_simple(), swb_flag, swb_index, and swb_state.

Referenced by RandI().

00212 {
00213   int i;
00214 
00215   if ( ! is_init )
00216     set_state_fsultra_simple(DEFAULT_SEED1, DEFAULT_SEED2);
00217 
00218   s[0] = (double)  swb_index;
00219   s[1] = (double)  swb_flag;
00220   s[2] = (double)  cong_state;
00221   for (i = 0 ; i < N ; i++) 
00222     s[i+3] = (double) (unsigned long) swb_state[i];
00223 }

Here is the call graph for this function:

Here is the caller graph for this function:

int set_state_fsultra ( double *  s  ) 

Definition at line 172 of file fsultra.c.

References cong_state, i, int, is_init, long, N, sciprint(), swb_flag, swb_index, and swb_state.

00173 { 
00174   double try;
00175   int i;
00176 
00177   try = s[0];
00178   if ( floor(try) != try || try < 0.0  ||  try > (double) N)
00179     {
00180       sciprint("\n\r the first component of the fsultra state, must be an integer in [0, %d] \n\r",N);
00181       return 0;
00182     }
00183   swb_index = (int) try;
00184 
00185   try = s[1];
00186   if ( try != 0.0  &&  try != 1.0)
00187     {
00188       sciprint("\n\r the second component of the fsultra state, must be 0 or 1 \n\r");
00189       return 0;
00190     }
00191   swb_flag = (int) try;
00192 
00193   try = s[2];
00194   if ( floor(try) != try  ||  try <= 0 ||  try > 4294967295.0 )
00195     {
00196       sciprint("\n\r the third component of the fsultra state, must be an integer in [1, 2^32-1] \n\r");
00197       return 0;
00198     }
00199   cong_state = (unsigned long) try;
00200  
00201   /* no verif here ... */
00202   for (i = 0 ; i < N ; i++) 
00203     swb_state[i] = (long) (((unsigned long) s[i+3]) & 0xffffffff);
00204 
00205   is_init = 1;
00206   return 1;
00207 }

Here is the call graph for this function:

int set_state_fsultra_simple ( double  s1,
double  s2 
)

Definition at line 138 of file fsultra.c.

References advance_state_swb(), cong_state, i, is_init, j, long, N, sciprint(), swb_flag, swb_index, and swb_state.

Referenced by fsultra(), get_state_fsultra(), and RandI().

00139 { 
00140   unsigned long shrgx, tidbits=0;
00141   int i, j;
00142 
00143   if (    (s1 == floor(s1) && 0.0 <= s1 && s1 <= 4294967295.0)
00144        && (s2 == floor(s2) && 0.0 <= s2 && s2 <= 4294967295.0) )
00145     {
00146       cong_state = ((unsigned long) s1)*2 + 1;
00147       shrgx = (unsigned long) s2;
00148       for ( i=0 ; i<N ; i++)
00149         {
00150           for ( j=32 ; j>0 ; j--)
00151             { 
00152               cong_state = cong_state * 69069;
00153               shrgx = shrgx ^ (shrgx >> 15);
00154               shrgx = shrgx ^ (shrgx << 17);
00155               tidbits = (tidbits>>1) | (0x80000000 & (cong_state^shrgx));
00156             }
00157           swb_state[i] = tidbits;
00158         }
00159       swb_index = 0;
00160       swb_flag = 0;
00161       advance_state_swb();  /* pour retrouver la même séquence que ds scilab V3.0 */
00162       is_init = 1;
00163       return 1;
00164     }
00165   else
00166     {
00167       sciprint("\n\r bad seed for fsultra, must be integers in [0, 2^32-1] \n\r");
00168       return 0;
00169     }
00170 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

unsigned long cong_state [static]

Definition at line 73 of file fsultra.c.

Referenced by fsultra(), get_state_fsultra(), set_state_fsultra(), and set_state_fsultra_simple().

double DEFAULT_SEED1 = 1234567.0 [static]

Definition at line 81 of file fsultra.c.

Referenced by fsultra(), and get_state_fsultra().

double DEFAULT_SEED2 = 7654321.0 [static]

Definition at line 81 of file fsultra.c.

Referenced by fsultra(), and get_state_fsultra().

int is_init = 0 [static]

Definition at line 69 of file fsultra.c.

int swb_flag [static]

Definition at line 72 of file fsultra.c.

Referenced by advance_state_swb(), get_state_fsultra(), set_state_fsultra(), and set_state_fsultra_simple().

int swb_index = N [static]

Definition at line 71 of file fsultra.c.

Referenced by advance_state_swb(), fsultra(), get_state_fsultra(), set_state_fsultra(), and set_state_fsultra_simple().

long swb_state[N] [static]

Definition at line 70 of file fsultra.c.

Referenced by advance_state_swb(), fsultra(), get_state_fsultra(), set_state_fsultra(), and set_state_fsultra_simple().


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