1 | |
---|
2 | (use eggdoc) |
---|
3 | |
---|
4 | (define doc |
---|
5 | `((eggdoc:begin |
---|
6 | (name "swb-random") |
---|
7 | (description "A random number generator based on the subtract-with-borrow (SWB) method.") |
---|
8 | (author (url "http://chicken.wiki.br/ivan raikov" "Ivan Raikov")) |
---|
9 | |
---|
10 | (history |
---|
11 | (version "1.5" "Bug fix in the setup file") |
---|
12 | (version "1.4" "Removed easyffi dependency") |
---|
13 | (version "1.3" "Build script updated for better cross-platform compatibility") |
---|
14 | (version "1.2" "Fixed the .meta file to include the documentation") |
---|
15 | (version "1.1" "License upgrade to GPL v3") |
---|
16 | (version "1.0" "Initial release")) |
---|
17 | |
---|
18 | (requires) |
---|
19 | |
---|
20 | (usage "(require-extension swb-random)") |
---|
21 | |
---|
22 | (download "swb-random.egg") |
---|
23 | |
---|
24 | (documentation |
---|
25 | |
---|
26 | (p "The swb-random library is a port of the SML/NJ implementation of " |
---|
27 | "a random number generator using the subtract-with-borrow (SWB) method " |
---|
28 | "described by Marsaglia and Zaman in " |
---|
29 | (pre "A New Class of Random Number Generators, " |
---|
30 | "Ann. Applied Prob. 1(3), 1991, pp. 462-480. ")) |
---|
31 | |
---|
32 | (p "The SWB generator implemented in this library is a 30-bit generator with lags 48 and 8. " |
---|
33 | "It has period " (tt "(2^1487 - 2^247)/105") " or about " (tt "10^445") |
---|
34 | ". The SWB generator acts locally like a lagged Fibonacci generator " |
---|
35 | "and thus it is combined with a linear congruential generator " |
---|
36 | (tt "(48271*a)mod(2^30-1)") ". ") |
---|
37 | |
---|
38 | (subsection "Procedures" |
---|
39 | |
---|
40 | (procedure "make-swb-random-state:: CONG-SEED SHR-SEED -> SWB-STATE" |
---|
41 | (p "Creates an initial seed array and generator state. " |
---|
42 | "The seed vector is filled one bit at a time by taking " |
---|
43 | "the leading bit of the xor of a shift register and a " |
---|
44 | "congruential sequence. The congruential generator is " |
---|
45 | (tt "(c*48271) mod (2^30 - 1)") ". The shift register " |
---|
46 | "generator is " (tt "c(I + L18)(I + R13)") ". " |
---|
47 | "The same congruential generator continues to be used as a " |
---|
48 | "mixing generator with the SWB generator.")) |
---|
49 | |
---|
50 | (procedure "swb-random!:: SWB-STATE -> FIXNUM" |
---|
51 | (p "Computes the next random number. The output from the SWB " |
---|
52 | "generator is xor-ed with a number from the linear " |
---|
53 | "congruential generator. This procedure modifies its input " |
---|
54 | "argument. ")) |
---|
55 | |
---|
56 | (procedure "swb-random-natural!:: SWB-STATE -> FIXNUM" |
---|
57 | (p "Computes the next random number and returns its absolute value. " |
---|
58 | "The output from the SWB generator is xor-ed with a number from the " |
---|
59 | "linear congruential generator. This procedure modifies its input " |
---|
60 | "argument. ")) |
---|
61 | |
---|
62 | (procedure "swb-random-real!:: SWB-STATE -> FLONUM" |
---|
63 | (p "Computes the two next random numbers and uses them to construct " |
---|
64 | "a real number of the range " (tt "[0..1]") ". " |
---|
65 | "The output from the SWB generator is xor-ed with a number from the " |
---|
66 | "linear congruential generator. This procedure modifies its input " |
---|
67 | "argument. ")) |
---|
68 | |
---|
69 | (procedure "swb-random-range!:: (FIXNUM * FIXNUM) -> (SWB-STATE -> FIXNUM)" |
---|
70 | (p "Given a range " (tt "[i..j], 0 <= i < j") ", returns a " |
---|
71 | "procedure that takes in a random number generator state and " |
---|
72 | "computes a random number in the given range. " |
---|
73 | "The output from the SWB generator is xor-ed with a number from the " |
---|
74 | "linear congruential generator. The returned procedure modifies its input " |
---|
75 | "argument. ")) |
---|
76 | |
---|
77 | (procedure "swb-random:: SWB-STATE -> SWB-STATE * FIXNUM" |
---|
78 | (p "Computes the next random number. The output from the SWB " |
---|
79 | "generator is xor-ed with a number from the linear " |
---|
80 | "congruential generator. The new generator state is returned along " |
---|
81 | "with the random number. ")) |
---|
82 | |
---|
83 | (procedure "swb-random-natural:: SWB-STATE -> SWB-STATE * FIXNUM" |
---|
84 | (p "Computes the next random number and returns its absolute values. " |
---|
85 | "The output from the SWB generator is xor-ed with a number from the linear " |
---|
86 | "congruential generator. The new generator state is returned along " |
---|
87 | "with the random number. ")) |
---|
88 | |
---|
89 | (procedure "swb-random-real:: SWB-STATE -> SWB-STATE * FLONUM" |
---|
90 | (p "Computes the two next random numbers and uses them to construct " |
---|
91 | "a real number of the range " (tt "[0..1]") ". " |
---|
92 | "The output from the SWB generator is xor-ed with a number from the " |
---|
93 | "linear congruential generator. The new generator state is returned along " |
---|
94 | "with the random number. ")) |
---|
95 | |
---|
96 | (procedure "swb-random-range:: (FIXNUM * FIXNUM) -> (SWB-STATE -> SWB-STATE * FIXNUM)" |
---|
97 | (p "Given a range " (tt "[i..j], 0 <= i < j") ", returns a " |
---|
98 | "procedure that takes in a random number generator state and " |
---|
99 | "computes a random number in the given range. " |
---|
100 | "The output from the SWB generator is xor-ed with a number from the " |
---|
101 | "linear congruential generator. The new generator state is returned along " |
---|
102 | "with the random number. ")))) |
---|
103 | |
---|
104 | |
---|
105 | (examples) |
---|
106 | |
---|
107 | (license |
---|
108 | "Copyright 2007 Ivan Raikov. |
---|
109 | |
---|
110 | This program is free software: you can redistribute it and/or modify |
---|
111 | it under the terms of the GNU General Public License as published by |
---|
112 | the Free Software Foundation, either version 3 of the License, or (at |
---|
113 | your option) any later version. |
---|
114 | |
---|
115 | This program is distributed in the hope that it will be useful, but |
---|
116 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
117 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
118 | General Public License for more details. |
---|
119 | |
---|
120 | A full copy of the GPL license can be found at |
---|
121 | <http://www.gnu.org/licenses/>.")))) |
---|
122 | |
---|
123 | (if (eggdoc->html doc) (void)) |
---|