]> git.sur5r.net Git - bacula/bacula/blob - bacula/autoconf/randpass.bc
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / bacula / autoconf / randpass.bc
1     /*
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,
5         1192-1201 (1988).]
6
7         The generation algorithm is:
8
9             I[j+1] = (I[j] × 16807) & 0x7FFFFFFF
10
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
15         poses no problem.
16
17         Designed and implemented in September 2002 by John Walker,
18         http://www.fourmilab.ch/.
19     */
20
21     /* Initialise state to default value of 1. */
22     
23     t = 1
24
25     /* Generate and return the next random byte, updating
26        the state t. */
27
28     define r() {
29         t = (t * 16807) % (2^31)
30         return ((t / 2048) % (2^8))
31     }
32     
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. */
37
38     define s(x) {
39         auto i, j
40         if (x == 0) { "Seed must be nonzero"; return }
41         t = x % (2^32)
42         /* Perform initial shuffle of state. */
43         for (i = 0; i < 11; i++) j = r()
44     }