1 #include "xrisk.h"
2 #include "risklibex.h"
3 
4 /*
5 unsigned char noise[1<<19];
6 
7 * Just read random numbers from a file *
8 * Supported by Kim Oyehus kim@lise.unit.no *
9 float ran_Kim()
10 {
11   static int virgin=1, seed=0;
12   int        n,a;
13   FILE      *stream;
14 
15   seed=(long int)time((time_t *)0);
16   seed%=1<<19;
17   if(virgin)
18     {
19       stream=fopen("../random_data/random.bin","r");
20       for(n=0; n<1<<19; n++) noise[n]=fgetc(stream);
21       fclose(stream);
22       virgin=0;
23     }
24   a=noise[seed++];
25   a=(a<<8)+noise[seed++];
26   a=(a<<8)+noise[seed++];
27   return((float)a/(1<<24));
28 }
29 
30 
31 #define rnd_mult 1566083941L
32 unsigned long random_risk()
33 {
34   static unsigned long int seed=0;
35 
36   if (!seed)
37     {
38       seed=(long int)time((time_t *)0);
39       srandom((int)time((time_t *)0));
40       srand48((long)time((time_t *)0));
41     }
42   seed = rnd_mult * seed + 1;
43   return(seed*(unsigned long)lrand48()*(unsigned long)random());
44 }
45 
46 float ran0()
47 {
48   static     float y,maxran,v[98];
49   float      dum;
50   static int iff=0;
51   int        j;
52   unsigned   i,k;
53   static int idum=0;
54 
55   if (!idum) idum=(int)time((time_t *)0);
56 
57   if (idum < 0 || iff == 0) {
58     iff=1;
59     i=2;
60     do {
61       k=i;
62       i<<=1;
63     } while (i);
64     maxran=k;
65     srand(idum);
66     idum=1;
67     for (j=1;j<=97;j++) dum+=rand();
68     for (j=1;j<=97;j++) v[j]=rand();
69     y=rand();
70   }
71   j=1+97.0*y/maxran;
72   if (j > 97 || j < 1) risk_exit("RAN0: This cannot happen.",LAST_ARG);
73   y=v[j];
74   v[j]=rand();
75   return(y/maxran);
76 }
77 */
78 
79 #define M1 259200
80 #define IA1 7141
81 #define IC1 54773
82 #define RM1 (1.0/M1)
83 #define M2 134456
84 #define IA2 8121
85 #define IC2 28411
86 #define RM2 (1.0/M2)
87 #define M3 243000
88 #define IA3 4561
89 #define IC3 51349
90 
91 /* Currently in use */
ran1()92 float ran1()
93 {
94   static long  ix1,ix2,ix3;
95   static float r[98];
96   float        temp;
97   static int   iff=0;
98   int          j;
99   static int   idum=666;
100 
101   if ( idum == 666 ) idum= -(int)(time((time_t *)0)%10007);
102 
103   if (idum < 0 || iff == 0) {
104     iff=1;
105     ix1=(IC1-(idum)) % M1;
106     ix1=(IA1*ix1+IC1) % M1;
107     ix2=ix1 % M2;
108     ix1=(IA1*ix1+IC1) % M1;
109     ix3=ix1 % M3;
110     for (j=1;j<=97;j++) {
111       ix1=(IA1*ix1+IC1) % M1;
112       ix2=(IA2*ix2+IC2) % M2;
113       r[j]=(ix1+ix2*RM2)*RM1;
114     }
115     idum=1;
116   }
117   ix1=(IA1*ix1+IC1) % M1;
118   ix2=(IA2*ix2+IC2) % M2;
119   ix3=(IA3*ix3+IC3) % M3;
120   j=1 + ((97*ix3)/M3);
121   if ((j > 97) || (j < 1))
122     risk_exit("RAN1: This cannot happen.(%d)",j,LAST_ARG);
123   temp=r[j];
124   r[j]=(ix1+ix2*RM2)*RM1;
125   return temp;
126 }
127 
128 #undef M1
129 #undef IA1
130 #undef IC1
131 #undef RM1
132 #undef M2
133 #undef IA2
134 #undef IC2
135 #undef RM2
136 #undef M3
137 #undef IA3
138 #undef IC3
139