00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "machine.h"
00031 #include <math.h>
00032 #include "sciprint.h"
00033
00034
00035 static long s1 = 1234567890 ;
00036 static long s2 = 123456789 ;
00037
00038 unsigned long clcg2()
00039 {
00040 register long k,z;
00041
00042
00043 k= s1 /53668;
00044 s1 =40014*(s1%53668)-k*12211;
00045 if (s1 < 0) s1 += 2147483563;
00046
00047
00048 k=s2/52774;
00049 s2=40692*(s2%52774)-k*3791;
00050 if (s2 < 0) s2 += 2147483399;
00051
00052
00053 z = s1 - s2;
00054 if (z < 0) z += 2147483562;
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 return( (unsigned long) z );
00066 }
00067
00068 int set_state_clcg2(double g1, double g2)
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 }
00086
00087 void get_state_clcg2(double g[])
00088 {
00089 g[0] = (double) s1;
00090 g[1] = (double) s2;
00091 }
00092