clcg2.c File Reference

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

Include dependency graph for clcg2.c:

Go to the source code of this file.

Functions

unsigned long clcg2 ()
int set_state_clcg2 (double g1, double g2)
void get_state_clcg2 (double g[])

Variables

static long s1 = 1234567890
static long s2 = 123456789


Function Documentation

unsigned long clcg2 (  ) 

Definition at line 38 of file clcg2.c.

References s1, s2, and z.

00039 {
00040   register long k,z;
00041 
00042   /*  s1 = a1*s1 mod m1  (Schrage 's method)  */
00043   k= s1 /53668;
00044   s1 =40014*(s1%53668)-k*12211;
00045   if (s1 < 0) s1 += 2147483563;
00046 
00047   /*  s2 = a2*s2 mod m2  (Schrage 's method)  */
00048   k=s2/52774;
00049   s2=40692*(s2%52774)-k*3791;
00050   if (s2 < 0) s2 += 2147483399;
00051 
00052   /* final step : z = s1-s2 mod m1-1  */
00053   z = s1 - s2;  /* here z is in [2-m2,m1-2] */
00054   if (z < 0) z += 2147483562;
00055 
00056   /* NOTE : in the  original implementation the final test is :
00057    *     if (z < 1) z += 2147483562;
00058    * 
00059    *   which is not exactly  z = s1-s2 mod (m1 - 1)
00060    *
00061    *   This is also why it is different from the version used by
00062    *   randlib.
00063    */
00064   
00065   return( (unsigned long) z );
00066 }

void get_state_clcg2 ( double  g[]  ) 

Definition at line 87 of file clcg2.c.

References s1, and s2.

Referenced by RandI().

00088 {
00089   g[0] = (double) s1;
00090   g[1] = (double) s2;
00091 }

Here is the caller graph for this function:

int set_state_clcg2 ( double  g1,
double  g2 
)

Definition at line 68 of file clcg2.c.

References long, s1, s2, and sciprint().

Referenced by RandI().

00069 {
00070   
00071   if ( g1 == floor(g1) && g2 == floor(g2)  && 
00072        1 <= g1 && g1 <= 2147483562    &&
00073        1 <= g2 && g2 <= 2147483398 )
00074     {
00075       s1 = (long) g1;
00076       s2 = (long) g2;
00077       return ( 1 );
00078     }
00079   else
00080     {
00081       sciprint("\n\r bad seeds for clcg2, must be integers with  s1 in [1, 2147483562]");
00082       sciprint("\n\r                                        and  s2 in [1, 2147483398]\n\r");
00083       return ( 0 );
00084     }
00085 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

long s1 = 1234567890 [static]

Definition at line 35 of file clcg2.c.

Referenced by adjust_pointer_in_string(), bounce4(), bounce_ball(), clcg2(), compgoto_out(), flush_comments(), foldminmax(), get_state_clcg2(), ioseta(), omit_non_f(), putlineno(), rd_Z(), realloc(), samefpconst(), scale_copy(), set_state_clcg2(), struct_eq(), tostring(), and XmuScanlineEqu().

long s2 = 123456789 [static]

Definition at line 36 of file clcg2.c.

Referenced by bounce4(), bounce_ball(), clcg2(), compgoto_out(), get_state_clcg2(), samefpconst(), scale_copy(), set_state_clcg2(), struct_eq(), and XmuScanlineEqu().


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