clcg4.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define Maxgen   100

Enumerations

enum  SeedType { InitialSeed, LastSeed, NewSeed }

Functions

int set_seed_clcg4 (int g, double s0, double s1, double s2, double s3)
void get_state_clcg4 (int g, double s[4])
void init_generator_clcg4 (int g, SeedType Where)
void advance_state_clcg4 (int g, int k)
int set_initial_seed_clcg4 (double s0, double s1, double s2, double s3)
unsigned long clcg4 (int g)


Define Documentation

#define Maxgen   100

Definition at line 4 of file clcg4.h.

Referenced by RandI(), and set_initial_seed_clcg4().


Enumeration Type Documentation

enum SeedType

Enumerator:
InitialSeed 
LastSeed 
NewSeed 

Definition at line 6 of file clcg4.h.


Function Documentation

void advance_state_clcg4 ( int  g,
int  k 
)

Definition at line 219 of file clcg4.c.

References a, b, Cg, i, Ig, init_clcg4(), init_generator_clcg4(), InitialSeed, is_init, j, m, MultModM(), v_default, and w_default.

Referenced by RandI().

00220 {
00221   long int b[4];
00222   int i, j;
00223 
00224   if (! is_init ) {init_clcg4(v_default,w_default); is_init = 1; };
00225 
00226   for ( j = 0 ; j < 4 ; j++ )
00227     {
00228       b[j] = a[j];
00229       for ( i = 1 ; i <= k ; i++ )
00230         b[j] = MultModM( b[j], b[j], m[j]);
00231       Ig[j][g] = MultModM ( b[j], Cg[j][g], m[j] );
00232     }
00233   init_generator_clcg4(g, InitialSeed);
00234 }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long clcg4 ( int  g  ) 

Definition at line 263 of file clcg4.c.

References Cg, init_clcg4(), is_init, s, v_default, and w_default.

Referenced by clcg4_with_gen().

00264 {
00265   /* Modif Bruno : the generator have now the form (1) in place of (2) */
00266 
00267   long k,s;
00268   double u;
00269 
00270   if (! is_init ) {init_clcg4(v_default,w_default); is_init = 1; };
00271 
00272   /*  advance the 4 LCG */
00273   s = Cg [0][g];  k = s / 46693;
00274   s = 45991 * (s - k * 46693) - k * 25884;
00275   if (s < 0) s = s + 2147483647;  Cg [0][g] = s;
00276  
00277   s = Cg [1][g];  k = s / 10339;
00278   s = 207707 * (s - k * 10339) - k * 870;
00279   if (s < 0) s = s + 2147483543;  Cg [1][g] = s;
00280 
00281   s = Cg [2][g];  k = s / 15499;
00282   s = 138556 * (s - k * 15499) - k * 3979;
00283   if (s < 0) s = s + 2147483423;  Cg [2][g] = s;
00284 
00285   s = Cg [3][g];  k = s / 43218;
00286   s = 49689 * (s - k * 43218) - k * 24121;
00287   if (s < 0) s = s + 2147483323;  Cg [3][g] = s;
00288 
00289   /*  final step */
00290   u = (double)(Cg[0][g] - Cg[1][g]) + (double)(Cg[2][g] - Cg[3][g]);
00291   /*  we must do  u mod 2147483647 with u in [- 4294966863 ; 4294967066 ] : */
00292   if (u < 0) u += 2147483647;
00293   if (u < 0) u += 2147483647;
00294   if (u >= 2147483647) u -= 2147483647;
00295   if (u >= 2147483647) u -= 2147483647;
00296 
00297   return ((unsigned long) u );
00298 
00299 }

Here is the call graph for this function:

Here is the caller graph for this function:

void get_state_clcg4 ( int  g,
double  s[4] 
)

Definition at line 193 of file clcg4.c.

References Cg, init_clcg4(), is_init, j, v_default, and w_default.

Referenced by RandI().

00194 {
00195   int j;
00196   if (! is_init ) {init_clcg4(v_default,w_default); is_init = 1; };
00197   for (j = 0; j < 4; j++)  s [j] = (double) Cg [j][g];
00198 }

Here is the call graph for this function:

Here is the caller graph for this function:

void init_generator_clcg4 ( int  g,
SeedType  Where 
)

Definition at line 200 of file clcg4.c.

References aw, Cg, Ig, init_clcg4(), InitialSeed, is_init, j, LastSeed, Lg, m, MultModM(), NewSeed, v_default, and w_default.

Referenced by advance_state_clcg4(), RandI(), set_initial_seed_clcg4(), and set_seed_clcg4().

00201 {
00202   int j;
00203   if (! is_init ) {init_clcg4(v_default,w_default); is_init = 1; };
00204   for (j = 0; j < 4; j++)
00205     {
00206       switch (Where)
00207         {
00208         case InitialSeed :
00209           Lg [j][g] = Ig [j][g];   break;
00210         case NewSeed :
00211           Lg [j][g] = MultModM (aw [j], Lg [j][g], m [j]);   break;
00212         case LastSeed :
00213           break;
00214         }
00215       Cg [j][g] = Lg [j][g];
00216     }
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

int set_initial_seed_clcg4 ( double  s0,
double  s1,
double  s2,
double  s3 
)

Definition at line 236 of file clcg4.c.

References avw, comp_aw_and_avw(), display_info_clcg4(), g, Ig, init_generator_clcg4(), InitialSeed, is_init, j, long, m, Maxgen, MultModM(), v_default, verif_seeds_clcg4(), and w_default.

Referenced by init_clcg4(), and RandI().

00237 {
00238   int g, j;
00239 
00240   if (! is_init )  comp_aw_and_avw(v_default,w_default);
00241 
00242   if ( ! verif_seeds_clcg4(s0, s1, s2, s3) )
00243     {
00244       display_info_clcg4();
00245       return ( 0 );
00246     };
00247 
00248   is_init = 1;
00249   Ig [0][0] = (long) s0;
00250   Ig [1][0] = (long) s1;
00251   Ig [2][0] = (long) s2;
00252   Ig [3][0] = (long) s3;
00253   init_generator_clcg4(0, InitialSeed);
00254   for (g = 1; g <= Maxgen; g++)
00255     {
00256       for (j = 0; j < 4; j++)
00257         Ig [j][g] = MultModM (avw [j], Ig [j][g-1], m [j]);
00258       init_generator_clcg4(g, InitialSeed);
00259     }
00260   return ( 1 );
00261 }

Here is the call graph for this function:

Here is the caller graph for this function:

int set_seed_clcg4 ( int  g,
double  s0,
double  s1,
double  s2,
double  s3 
)

Definition at line 172 of file clcg4.c.

References display_info_clcg4(), Ig, init_clcg4(), init_generator_clcg4(), InitialSeed, is_init, long, sciprint(), v_default, verif_seeds_clcg4(), and w_default.

Referenced by RandI().

00173 {
00174   if (! is_init ) {init_clcg4(v_default,w_default); is_init = 1; };
00175 
00176   if ( verif_seeds_clcg4(s0, s1, s2, s3) )
00177     {
00178       Ig [0][g] = (long) s0; Ig [1][g] = (long) s1;
00179       Ig [2][g] = (long) s2; Ig [3][g] = (long) s3;
00180       init_generator_clcg4(g, InitialSeed);
00181       sciprint("\n\r => be aware that you have may lost synchronization");
00182       sciprint("\n\r    between the virtual gen %d and the others !", g);
00183       sciprint("\n\r    use grand(\"setall\", s1, s2, s3, s4) if you want recover it.");
00184       return ( 1 );
00185     }
00186   else
00187     {
00188       display_info_clcg4();
00189       return ( 0 );
00190     }
00191 }

Here is the call graph for this function:

Here is the caller graph for this function:


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