2 "bc" implementation of the "Minimal Standard"
3 multiplicative congruential generator of Park and Miller.
4 [Park, S.K. and K.W. Miller, Communications of the ACM 31,
7 The generation algorithm is:
9 I[j+1] = (I[j] × 16807) & 0x7FFFFFFF
11 Note that the intermediate value of the multiplication by 16807
12 (7^5) exceeds that representable in 32 bits; this has
13 deterred use of this generator in most portable languages.
14 Fortunately, bc computes with arbitrary precision so this
17 Designed and implemented in September 2002 by John Walker,
18 http://www.fourmilab.ch/.
21 /* Initialise state to default value of 1. */
25 /* Generate and return the next random byte, updating
29 t = (t * 16807) % (2^31)
30 return ((t / 2048) % (2^8))
33 /* Set the seed to the x argument. The state t is
34 set from the seed, after an initial shuffle. If
35 you don't want 0 printed when setting the seed,
36 assign s(x) to a junk variable. */
40 if (x == 0) { "Seed must be nonzero"; return }
42 /* Perform initial shuffle of state. */
43 for (i = 0; i < 11; i++) j = r()