comparison src/rand.cc @ 1255:fa24599e3d2c

[project @ 1995-04-11 17:49:27 by jwe]
author jwe
date Tue, 11 Apr 1995 17:49:27 +0000
parents 5cca5ae20299
children 611d403c7f3d
comparison
equal deleted inserted replaced
1254:ecf3dc595ecb 1255:fa24599e3d2c
41 // Current distribution of random numbers. 41 // Current distribution of random numbers.
42 static rand_dist current_distribution = uniform; 42 static rand_dist current_distribution = uniform;
43 43
44 extern "C" 44 extern "C"
45 { 45 {
46 int *F77_FCN (dgennor) (const double&, const double&, double&); 46 int *F77_FCN (dgennor, DGENNOR) (const double&, const double&,
47 int *F77_FCN (dgenunf) (const double&, const double&, double&); 47 double&);
48 int *F77_FCN (setall) (const int&, const int&); 48
49 int *F77_FCN (getsd) (int&, int&); 49 int *F77_FCN (dgenunf, DGENUNF) (const double&, const double&,
50 double&);
51
52 int *F77_FCN (setall, SETALL) (const int&, const int&);
53
54 int *F77_FCN (getsd, GETSD) (int&, int&);
50 } 55 }
51 56
52 static double 57 static double
53 curr_rand_seed (void) 58 curr_rand_seed (void)
54 { 59 {
55 union d2i { double d; int i[2]; }; 60 union d2i { double d; int i[2]; };
56 union d2i u; 61 union d2i u;
57 F77_FCN (getsd) (u.i[0], u.i[1]); 62 F77_FCN (getsd, GETSD) (u.i[0], u.i[1]);
58 return u.d; 63 return u.d;
59 } 64 }
60 65
61 static int 66 static int
62 force_to_fit_range (int i, int lo, int hi) 67 force_to_fit_range (int i, int lo, int hi)
79 union d2i { double d; int i[2]; }; 84 union d2i { double d; int i[2]; };
80 union d2i u; 85 union d2i u;
81 u.d = val; 86 u.d = val;
82 int i0 = force_to_fit_range (u.i[0], 1, 2147483563); 87 int i0 = force_to_fit_range (u.i[0], 1, 2147483563);
83 int i1 = force_to_fit_range (u.i[1], 1, 2147483399); 88 int i1 = force_to_fit_range (u.i[1], 1, 2147483399);
84 F77_FCN (setall) (i0, i1); 89 F77_FCN (setall, SETALL) (i0, i1);
85 } 90 }
86 91
87 static char * 92 static char *
88 curr_rand_dist (void) 93 curr_rand_dist (void)
89 { 94 {
145 int s1 = hour * minute * second; 150 int s1 = hour * minute * second;
146 #endif 151 #endif
147 s0 = force_to_fit_range (s0, 1, 2147483563); 152 s0 = force_to_fit_range (s0, 1, 2147483563);
148 s1 = force_to_fit_range (s1, 1, 2147483399); 153 s1 = force_to_fit_range (s1, 1, 2147483399);
149 154
150 F77_FCN (setall) (s0, s1); 155 F77_FCN (setall, SETALL) (s0, s1);
151 initialized = 1; 156 initialized = 1;
152 } 157 }
153 158
154 int n = 0; 159 int n = 0;
155 int m = 0; 160 int m = 0;
268 { 273 {
269 double val; 274 double val;
270 switch (current_distribution) 275 switch (current_distribution)
271 { 276 {
272 case uniform: 277 case uniform:
273 F77_FCN (dgenunf) (0.0, 1.0, val); 278 F77_FCN (dgenunf, DGENUNF) (0.0, 1.0, val);
274 rand_mat.elem (i, j) = val; 279 rand_mat.elem (i, j) = val;
275 break; 280 break;
276 281
277 case normal: 282 case normal:
278 F77_FCN (dgennor) (0.0, 1.0, val); 283 F77_FCN (dgennor, DGENNOR) (0.0, 1.0, val);
279 rand_mat.elem (i, j) = val; 284 rand_mat.elem (i, j) = val;
280 break; 285 break;
281 286
282 default: 287 default:
283 panic_impossible (); 288 panic_impossible ();