com.c

filter: Statementstmt 59.1% 71 / 120 Branchbran 52.7% 19 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 57.6% 90 / 156 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« ranlib.c ↑ Summary circulant.c »
1 #include "ranlib.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 0 void advnst(long k)
5 /*
6 **********************************************************************
7 void advnst(long k)
8 ADV-a-N-ce ST-ate
9 Advances the state of the current generator by 2^K values and
10 resets the initial seed to that value.
11 This is a transcription from Pascal to Fortran of routine
12 Advance_State from the paper
13 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
14 with Splitting Facilities." ACM Transactions on Mathematical
15 Software, 17:98-111 (1991)
16 Arguments
17 k -> The generator is advanced by2^K values
18 **********************************************************************
19 */
20 {
21 #define numg 32L
22 extern void gsrgs(long getset,long *qvalue);
23 extern void gscgn(long getset,long *g);
24 extern long Xm1,Xm2,Xa1,Xa2,Xcg1[],Xcg2[];
25 static long g,i,ib1,ib2;
26 static long qrgnin;
27 /*
28 Abort unless random number generator initialized
29 */
30 0 gsrgs(0L,&qrgnin);
31 0 ▶ if(qrgnin) goto S10;
Branch: 1 branch
BranchTrueFalseTotal
if(qrgnin) goto S10; 0 0 0
32 0 fputs(" ADVNST called before random generator initialized - ABORT",stderr);
33 0 exit(1);
34 0 S10:
35 0 gscgn(0L,&g);
36 0 ib1 = Xa1;
37 0 ib2 = Xa2;
38 0 ▶ for(i=1; i<=k; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i<=k; i++) { 0 0 0
39 0 ib1 = mltmod(ib1,ib1,Xm1);
40 0 ib2 = mltmod(ib2,ib2,Xm2);
41 }
42 0 setsd(mltmod(ib1,*(Xcg1+g-1),Xm1),mltmod(ib2,*(Xcg2+g-1),Xm2));
43 /*
44 NOW, IB1 = A1**K AND IB2 = A2**K
45 */
46 #undef numg
47 0 }
48 4 void getsd(long *iseed1,long *iseed2)
49 /*
50 **********************************************************************
51 void getsd(long *iseed1,long *iseed2)
52 GET SeeD
53 Returns the value of two integer seeds of the current generator
54 This is a transcription from Pascal to Fortran of routine
55 Get_State from the paper
56 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
57 with Splitting Facilities." ACM Transactions on Mathematical
58 Software, 17:98-111 (1991)
59 Arguments
60 iseed1 <- First integer seed of generator G
61 iseed2 <- Second integer seed of generator G
62 **********************************************************************
63 */
64 {
65 #define numg 32L
66 extern void gsrgs(long getset,long *qvalue);
67 extern void gscgn(long getset,long *g);
68 extern long Xcg1[],Xcg2[];
69 static long g;
70 static long qrgnin;
71 /*
72 Abort unless random number generator initialized
73 */
74 4 gsrgs(0L,&qrgnin);
75 4 ▶ if(qrgnin) goto S10;
Branch: 1 branch
BranchTrueFalseTotal
if(qrgnin) goto S10; 4 0 4
76 0 fprintf(stderr,"%s\n",
77 " GETSD called before random number generator initialized -- abort!");
78 0 exit(0);
79 4 S10:
80 4 gscgn(0L,&g);
81 4 *iseed1 = *(Xcg1+g-1);
82 4 *iseed2 = *(Xcg2+g-1);
83 #undef numg
84 4 }
85 485 long ignlgi(void)
86 /*
87 **********************************************************************
88 long ignlgi(void)
89 GeNerate LarGe Integer
90 Returns a random integer following a uniform distribution over
91 (1, 2147483562) using the current generator.
92 This is a transcription from Pascal to Fortran of routine
93 Random from the paper
94 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
95 with Splitting Facilities." ACM Transactions on Mathematical
96 Software, 17:98-111 (1991)
97 **********************************************************************
98 */
99 {
100 #define numg 32L
101 extern void gsrgs(long getset,long *qvalue);
102 extern void gssst(long getset,long *qset);
103 extern void gscgn(long getset,long *g);
104 extern void inrgcm(void);
105 extern long Xm1,Xm2,Xa1,Xa2,Xcg1[],Xcg2[];
106 extern long Xqanti[];
107 static long ignlgi,curntg,k,s1,s2,z;
108 static long qqssd,qrgnin;
109 /*
110 IF THE RANDOM NUMBER PACKAGE HAS NOT BEEN INITIALIZED YET, DO SO.
111 IT CAN BE INITIALIZED IN ONE OF TWO WAYS : 1) THE FIRST CALL TO
112 THIS ROUTINE 2) A CALL TO SETALL.
113 */
114 485 gsrgs(0L,&qrgnin);
115 485 ▶ if(!qrgnin) inrgcm();
Branch: 1 branch
BranchTrueFalseTotal
if(!qrgnin) inrgcm(); 1 484 485
116 485 gssst(0,&qqssd);
117 485 ▶ if(!qqssd) setall(1234567890L,123456789L);
Branch: 1 branch
BranchTrueFalseTotal
if(!qqssd) setall(1234567890L,123456789L); 1 484 485
118 /*
119 Get Current Generator
120 */
121 485 gscgn(0L,&curntg);
122 485 s1 = *(Xcg1+curntg-1);
123 485 s2 = *(Xcg2+curntg-1);
124 485 k = s1/53668L;
125 485 s1 = Xa1*(s1-k*53668L)-k*12211;
126 485 ▶ if(s1 < 0) s1 += Xm1;
Branch: 1 branch
BranchTrueFalseTotal
if(s1 < 0) s1 += Xm1; 54 431 485
127 485 k = s2/52774L;
128 485 s2 = Xa2*(s2-k*52774L)-k*3791;
129 485 ▶ if(s2 < 0) s2 += Xm2;
Branch: 1 branch
BranchTrueFalseTotal
if(s2 < 0) s2 += Xm2; 17 468 485
130 485 *(Xcg1+curntg-1) = s1;
131 485 *(Xcg2+curntg-1) = s2;
132 485 z = s1-s2;
133 485 ▶ if(z < 1) z += (Xm1-1);
Branch: 1 branch
BranchTrueFalseTotal
if(z < 1) z += (Xm1-1); 235 250 485
134 485 ▶ if(*(Xqanti+curntg-1)) z = Xm1-z;
Branch: 1 branch
BranchTrueFalseTotal
if(*(Xqanti+curntg-1)) z = Xm1-z; 0 485 485
135 485 ignlgi = z;
136 485 return ignlgi;
137 #undef numg
138 }
139 160 void initgn(long isdtyp)
140 /*
141 **********************************************************************
142 void initgn(long isdtyp)
143 INIT-ialize current G-e-N-erator
144 Reinitializes the state of the current generator
145 This is a transcription from Pascal to Fortran of routine
146 Init_Generator from the paper
147 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
148 with Splitting Facilities." ACM Transactions on Mathematical
149 Software, 17:98-111 (1991)
150 Arguments
151 isdtyp -> The state to which the generator is to be set
152 isdtyp = -1 => sets the seeds to their initial value
153 isdtyp = 0 => sets the seeds to the first value of
154 the current block
155 isdtyp = 1 => sets the seeds to the first value of
156 the next block
157 **********************************************************************
158 */
159 {
160 #define numg 32L
161 extern void gsrgs(long getset,long *qvalue);
162 extern void gscgn(long getset,long *g);
163 extern long Xm1,Xm2,Xa1w,Xa2w,Xig1[],Xig2[],Xlg1[],Xlg2[],Xcg1[],Xcg2[];
164 static long g;
165 static long qrgnin;
166 /*
167 Abort unless random number generator initialized
168 */
169 160 gsrgs(0L,&qrgnin);
170 160 ▶ if(qrgnin) goto S10;
Branch: 1 branch
BranchTrueFalseTotal
if(qrgnin) goto S10; 160 0 160
171 0 fprintf(stderr,"%s\n",
172 " INITGN called before random number generator initialized -- abort!");
173 0 exit(1);
174 160 S10:
175 160 gscgn(0L,&g);
176 160 ▶ if(-1 != isdtyp) goto S20;
Branch: 1 branch
BranchTrueFalseTotal
if(-1 != isdtyp) goto S20; 0 160 160
177 160 *(Xlg1+g-1) = *(Xig1+g-1);
178 160 *(Xlg2+g-1) = *(Xig2+g-1);
179 160 goto S50;
180 0 S20:
181 0 ▶ if(0 != isdtyp) goto S30;
Branch: 1 branch
BranchTrueFalseTotal
if(0 != isdtyp) goto S30; 0 0 0
182 0 goto S50;
183 0 S30:
184 /*
185 do nothing
186 */
187 0 ▶ if(1 != isdtyp) goto S40;
Branch: 1 branch
BranchTrueFalseTotal
if(1 != isdtyp) goto S40; 0 0 0
188 0 *(Xlg1+g-1) = mltmod(Xa1w,*(Xlg1+g-1),Xm1);
189 0 *(Xlg2+g-1) = mltmod(Xa2w,*(Xlg2+g-1),Xm2);
190 0 goto S50;
191 0 S40:
192 0 fprintf(stderr,"%s\n","isdtyp not in range in INITGN");
193 0 exit(1);
194 160 S50:
195 160 *(Xcg1+g-1) = *(Xlg1+g-1);
196 160 *(Xcg2+g-1) = *(Xlg2+g-1);
197 #undef numg
198 160 }
199 1 void inrgcm(void)
200 /*
201 **********************************************************************
202 void inrgcm(void)
203 INitialize Random number Generator CoMmon
204 Function
205 Initializes common area for random number generator. This saves
206 the nuisance of a BLOCK DATA routine and the difficulty of
207 assuring that the routine is loaded with the other routines.
208 **********************************************************************
209 */
210 {
211 #define numg 32L
212 extern void gsrgs(long getset,long *qvalue);
213 extern long Xm1,Xm2,Xa1,Xa2,Xa1w,Xa2w,Xa1vw,Xa2vw;
214 extern long Xqanti[];
215 static long T1;
216 static long i;
217 /*
218 V=20; W=30;
219 A1W = MOD(A1**(2**W),M1) A2W = MOD(A2**(2**W),M2)
220 A1VW = MOD(A1**(2**(V+W)),M1) A2VW = MOD(A2**(2**(V+W)),M2)
221 If V or W is changed A1W, A2W, A1VW, and A2VW need to be recomputed.
222 An efficient way to precompute a**(2*j) MOD m is to start with
223 a and square it j times modulo m using the function MLTMOD.
224 */
225 1 Xm1 = 2147483563L;
226 1 Xm2 = 2147483399L;
227 1 Xa1 = 40014L;
228 1 Xa2 = 40692L;
229 1 Xa1w = 1033780774L;
230 1 Xa2w = 1494757890L;
231 1 Xa1vw = 2082007225L;
232 1 Xa2vw = 784306273L;
233 33 ▶ for(i=0; i<numg; i++) *(Xqanti+i) = 0;
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i<numg; i++) *(Xqanti+i) = 0; 32 1 33
234 1 T1 = 1;
235 /*
236 Tell the world that common has been initialized
237 */
238 1 gsrgs(1L,&T1);
239 #undef numg
240 1 }
241 5 void setall(long iseed1,long iseed2)
242 /*
243 **********************************************************************
244 void setall(long iseed1,long iseed2)
245 SET ALL random number generators
246 Sets the initial seed of generator 1 to ISEED1 and ISEED2. The
247 initial seeds of the other generators are set accordingly, and
248 all generators states are set to these seeds.
249 This is a transcription from Pascal to Fortran of routine
250 Set_Initial_Seed from the paper
251 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
252 with Splitting Facilities." ACM Transactions on Mathematical
253 Software, 17:98-111 (1991)
254 Arguments
255 iseed1 -> First of two integer seeds
256 iseed2 -> Second of two integer seeds
257 **********************************************************************
258 */
259 {
260 #define numg 32L
261 extern void gsrgs(long getset,long *qvalue);
262 extern void gssst(long getset,long *qset);
263 extern void gscgn(long getset,long *g);
264 extern long Xm1,Xm2,Xa1vw,Xa2vw,Xig1[],Xig2[];
265 static long T1;
266 static long g,ocgn;
267 static long qrgnin;
268 5 T1 = 1;
269 /*
270 TELL IGNLGI, THE ACTUAL NUMBER GENERATOR, THAT THIS ROUTINE
271 HAS BEEN CALLED.
272 */
273 5 gssst(1,&T1);
274 5 gscgn(0L,&ocgn);
275 /*
276 Initialize Common Block if Necessary
277 */
278 5 gsrgs(0L,&qrgnin);
279 5 ▶ if(!qrgnin) inrgcm();
Branch: 1 branch
BranchTrueFalseTotal
if(!qrgnin) inrgcm(); 0 5 5
280 5 *Xig1 = iseed1;
281 5 *Xig2 = iseed2;
282 5 initgn(-1L);
283 160 ▶ for(g=2; g<=numg; g++) {
Branch: 1 branch
BranchTrueFalseTotal
for(g=2; g<=numg; g++) { 155 5 160
284 155 *(Xig1+g-1) = mltmod(Xa1vw,*(Xig1+g-2),Xm1);
285 155 *(Xig2+g-1) = mltmod(Xa2vw,*(Xig2+g-2),Xm2);
286 155 gscgn(1L,&g);
287 155 initgn(-1L);
288 }
289 5 gscgn(1L,&ocgn);
290 #undef numg
291 5 }
292 0 void setant(long qvalue)
293 /*
294 **********************************************************************
295 void setant(long qvalue)
296 SET ANTithetic
297 Sets whether the current generator produces antithetic values. If
298 X is the value normally returned from a uniform [0,1] random
299 number generator then 1 - X is the antithetic value. If X is the
300 value normally returned from a uniform [0,N] random number
301 generator then N - 1 - X is the antithetic value.
302 All generators are initialized to NOT generate antithetic values.
303 This is a transcription from Pascal to Fortran of routine
304 Set_Antithetic from the paper
305 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
306 with Splitting Facilities." ACM Transactions on Mathematical
307 Software, 17:98-111 (1991)
308 Arguments
309 qvalue -> nonzero if generator G is to generating antithetic
310 values, otherwise zero
311 **********************************************************************
312 */
313 {
314 #define numg 32L
315 extern void gsrgs(long getset,long *qvalue);
316 extern void gscgn(long getset,long *g);
317 extern long Xqanti[];
318 static long g;
319 static long qrgnin;
320 /*
321 Abort unless random number generator initialized
322 */
323 0 gsrgs(0L,&qrgnin);
324 0 ▶ if(qrgnin) goto S10;
Branch: 1 branch
BranchTrueFalseTotal
if(qrgnin) goto S10; 0 0 0
325 0 fprintf(stderr,"%s\n",
326 " SETANT called before random number generator initialized -- abort!");
327 0 exit(1);
328 0 S10:
329 0 gscgn(0L,&g);
330 0 Xqanti[g-1] = qvalue;
331 #undef numg
332 0 }
333 0 void setsd(long iseed1,long iseed2)
334 /*
335 **********************************************************************
336 void setsd(long iseed1,long iseed2)
337 SET S-ee-D of current generator
338 Resets the initial seed of the current generator to ISEED1 and
339 ISEED2. The seeds of the other generators remain unchanged.
340 This is a transcription from Pascal to Fortran of routine
341 Set_Seed from the paper
342 L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
343 with Splitting Facilities." ACM Transactions on Mathematical
344 Software, 17:98-111 (1991)
345 Arguments
346 iseed1 -> First integer seed
347 iseed2 -> Second integer seed
348 **********************************************************************
349 */
350 {
351 #define numg 32L
352 extern void gsrgs(long getset,long *qvalue);
353 extern void gscgn(long getset,long *g);
354 extern long Xig1[],Xig2[];
355 static long g;
356 static long qrgnin;
357 /*
358 Abort unless random number generator initialized
359 */
360 0 gsrgs(0L,&qrgnin);
361 0 ▶ if(qrgnin) goto S10;
Branch: 1 branch
BranchTrueFalseTotal
if(qrgnin) goto S10; 0 0 0
362 0 fprintf(stderr,"%s\n",
363 " SETSD called before random number generator initialized -- abort!");
364 0 exit(1);
365 0 S10:
366 0 gscgn(0L,&g);
367 0 *(Xig1+g-1) = iseed1;
368 0 *(Xig2+g-1) = iseed2;
369 0 initgn(-1L);
370 #undef numg
371 0 }
372 long Xm1,Xm2,Xa1,Xa2,Xcg1[32],Xcg2[32],Xa1w,Xa2w,Xig1[32],Xig2[32],Xlg1[32],
373 Xlg2[32],Xa1vw,Xa2vw;
374 long Xqanti[32];
« ranlib.c ↑ Summary circulant.c »