2 * c A random number generator called as a function by c cwrandom
3 * (iseed) or irandm (iseed) c The parameter should be a
4 * pointer to a 2-element long vector. c The first call gives a double
5 * uniform in 0 .. 1. c The second gives an long integer uniform in 0 ..
6 * 2**31-1 c Both update iseed[] in exactly the same way. c iseed[] must
7 * be a 2-element integer vector. c The initial value of the second
8 * element may be anything. c c The period of the random sequence is 2**32 *
9 * (2**32-1) c The table mt[0:127] is defined by mt[i] = 69069 ** (128-i)
11 * c From Chris Wallace, via Tim Shimmin c Top-level call rnd, srnd
12 * added by Justin Zobel
15 #define MASK ((long) 593970775)
16 /* or in hex, 23674657 */
17 #define SCALE ((double) 1.0 / (1024.0 * 1024.0 * 1024.0 * 2.0))
18 /* i.e. 2 to power -31 */
20 static long mt [128] = {
153 cwrandom(long is [2])
160 it = (it + it) ^ MASK;
164 /* to ensure all-ones pattern omitted */
165 leh = leh * mt[nit & 127] + nit;
170 return (SCALE * ((long)(leh | 1)));
182 it = (it + it) ^ MASK;
186 /* to ensure all-ones pattern omitted */
187 leh = leh * mt[nit & 127] + nit;
197 static long seeds[2];
202 return irandm(seeds);
208 seeds[0] = seeds[1] = seed;