1 | |
---|
2 | (use eggdoc) |
---|
3 | |
---|
4 | (define doc |
---|
5 | `((eggdoc:begin |
---|
6 | (name "random-mtzig") |
---|
7 | |
---|
8 | (description "An implementation of the MT19937 random number generator with Marsaglia and Tang's Ziggurat algorithm to generate random numbers from a non-uniform distribution.") |
---|
9 | |
---|
10 | (author (url "http://chicken.wiki.br/users/ivan-raikov" "Ivan Raikov")) |
---|
11 | |
---|
12 | (history |
---|
13 | (version "2.8" "Ported to Chicken 4") |
---|
14 | (version "2.7" "Added binomial sampling procedures") |
---|
15 | (version "2.6" "Build script updated for better cross-platform compatibility") |
---|
16 | (version "2.5" "Example updated to match 2.0 API [thanks to Terrence Brannon]") |
---|
17 | (version "2.4" "Bug fix in random-mtzig:f32vector-rande!") |
---|
18 | (version "2.3" "C interface bug fixes") |
---|
19 | (version "2.2" "Changed type definition for uint64_t so it doesn't collide with stdint.h") |
---|
20 | (version "2.1" "Bug fix in init procedure for vector case") |
---|
21 | (version "2.0" "Created reentrant interface") |
---|
22 | (version "1.0" "Initial release")) |
---|
23 | |
---|
24 | (requires) |
---|
25 | |
---|
26 | (usage "(require-extension random-mtzig)") |
---|
27 | |
---|
28 | (download "random-mtzig.egg") |
---|
29 | |
---|
30 | (documentation |
---|
31 | |
---|
32 | (p "The " (tt "random-mtzig") " library is Chicken Scheme wrapper for the MT19937 " |
---|
33 | "random number generator used in " (url "http://www.gnu.org/software/octave/" "GNU Octave") |
---|
34 | ". ") |
---|
35 | |
---|
36 | (subsection "Procedures" |
---|
37 | |
---|
38 | (procedure "random-mtzig:init :: [SEED] -> STATE" |
---|
39 | (p "Creates an initial seed array and returns the corresponding generator state vector. " |
---|
40 | "If the optional " (tt "SEED") " is not specified, " |
---|
41 | "the generator is initialized with a seed from " (tt "/dev/urandom") |
---|
42 | " or with the current time in seconds. " |
---|
43 | "If " (tt "SEED") " can be an integer or an " (tt "u32vector") ". ")) |
---|
44 | |
---|
45 | |
---|
46 | (procedure "random-mtzig:random! :: STATE -> INTEGER" |
---|
47 | (p "Returns a random integer value between 0 and the largest " |
---|
48 | "machine-representable unsigned integer on the current platform. ")) |
---|
49 | |
---|
50 | |
---|
51 | (procedure "random-mtzig:randu! :: STATE -> NUMBER" |
---|
52 | (p "Returns a random value from a uniform distribution on the " |
---|
53 | "interval " (tt "(0, 1)") ". ")) |
---|
54 | |
---|
55 | (procedure "random-mtzig:randn! :: STATE -> NUMBER" |
---|
56 | (p "Returns a random value from a normal (Gaussian) distribution, using " |
---|
57 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
58 | "a uniform distribution into a normal one. ")) |
---|
59 | |
---|
60 | (procedure "random-mtzig:rande! :: STATE -> NUMBER" |
---|
61 | (p "Returns a random value from an exponential distribution, using " |
---|
62 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
63 | "a uniform distribution into an exponential one. ")) |
---|
64 | |
---|
65 | (procedure "random-mtzig:randb! :: N * P * STATE -> NUMBER" |
---|
66 | (p "Returns a random value from a binomial distribution with " |
---|
67 | (tt "N") " experiments and probability " (tt "P") ". ")) |
---|
68 | |
---|
69 | (procedure "random-mtzig:f64vector-randu! :: N * STATE -> F64VECTOR" |
---|
70 | (p "Returns an SRFI-4 " (tt "f64") " vector of random values " |
---|
71 | "from a uniform distribution on the interval " (tt "(0, 1)") ". ")) |
---|
72 | |
---|
73 | (procedure "random-mtzig:f64vector-randn! :: N * STATE -> F64VECTOR" |
---|
74 | (p "Returns an SRFI-4 " (tt "f64") " vector of random values " |
---|
75 | " from a normal (Gaussian) distribution, using " |
---|
76 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
77 | "a uniform distribution into a normal one. ")) |
---|
78 | |
---|
79 | (procedure "random-mtzig:f64vector-rande! :: N * STATE -> F64VECTOR" |
---|
80 | (p "Returns an SRFI-4 " (tt "f64") " vector of random values " |
---|
81 | " from am exponential distribution, using " |
---|
82 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
83 | "a uniform distribution into an exponential one. ")) |
---|
84 | |
---|
85 | (procedure "random-mtzig:f64vector-randb! :: N * P * XN * STATE -> F64VECTOR" |
---|
86 | (p "Returns an SRFI-4 " (tt "f64") " vector of random values " |
---|
87 | "from a binomial distribution with " (tt "N") |
---|
88 | " experiments and probability " (tt "P") ". ")) |
---|
89 | |
---|
90 | (procedure "random-mtzig:f32vector-randu! :: N * STATE -> F64VECTOR" |
---|
91 | (p "Returns an SRFI-4 " (tt "f32") " vector of random values " |
---|
92 | "from a uniform distribution on the interval " (tt "(0, 1)") ". ")) |
---|
93 | |
---|
94 | (procedure "random-mtzig:f32vector-randn! :: N * STATE -> F64VECTOR" |
---|
95 | (p "Returns an SRFI-4 " (tt "f32") " vector of random values " |
---|
96 | " from a normal (Gaussian) distribution, using " |
---|
97 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
98 | "a uniform distribution into a normal one. ")) |
---|
99 | |
---|
100 | (procedure "random-mtzig:f32vector-rande! :: N * STATE -> F64VECTOR" |
---|
101 | (p "Returns an SRFI-4 " (tt "f32") " vector of random values " |
---|
102 | " from am exponential distribution, using " |
---|
103 | "Marsaglia and Tsang's Ziggurat algorithm to transform " |
---|
104 | "a uniform distribution into an exponential one. ")) |
---|
105 | |
---|
106 | (procedure "random-mtzig:f32vector-randb! :: N * P * XN * STATE -> F64VECTOR" |
---|
107 | (p "Returns an SRFI-4 " (tt "f32") " vector of random values " |
---|
108 | "from a binomial distribution with " (tt "N") |
---|
109 | " experiments and probability " (tt "P") ". ")))) |
---|
110 | |
---|
111 | |
---|
112 | (examples (pre #<<EOF |
---|
113 | csi> (require-extension random-mtzig) |
---|
114 | csi> (define st (random-mtzig:init 24)) |
---|
115 | csi> (random-mtzig:f64vector-randu! 20 st) |
---|
116 | #f64(0.960017303335919 0.699512049949576 0.999867292623879 0.220067299782852 |
---|
117 | 0.361056353964058 0.739840990209437 0.996455725089097 0.316346977790608 |
---|
118 | 0.136544579823525 0.3839800101516 0.320519283565193 0.366414753083515 |
---|
119 | 0.709651562588127 0.900142430523374 0.534115439197721 0.247293764909945 |
---|
120 | 0.671806562577075 0.561729107313138 0.54255987670951 0.893447603694901) |
---|
121 | EOF |
---|
122 | )) |
---|
123 | |
---|
124 | (license |
---|
125 | "Chicken Scheme egg scripts and documentation Copyright 2007-2009 Ivan Raikov. |
---|
126 | |
---|
127 | Coded by Takuji Nishimura and Makoto Matsumoto. |
---|
128 | This is a faster version by taking Shawn Cokus's optimization, |
---|
129 | Matthe Bellew's simplification, Isaku Wada's real version. |
---|
130 | David Bateman added normal and exponential distributions following |
---|
131 | Marsaglia and Tang's Ziggurat algorithm. |
---|
132 | |
---|
133 | Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, |
---|
134 | Copyright (C) 2004, David Bateman |
---|
135 | All rights reserved. |
---|
136 | |
---|
137 | Redistribution and use in source and binary forms, with or without |
---|
138 | modification, are permitted provided that the following conditions |
---|
139 | are met: |
---|
140 | |
---|
141 | 1. Redistributions of source code must retain the above copyright |
---|
142 | notice, this list of conditions and the following disclaimer. |
---|
143 | |
---|
144 | 2. Redistributions in binary form must reproduce the above copyright |
---|
145 | notice, this list of conditions and the following disclaimer in the |
---|
146 | documentation and/or other materials provided with the distribution. |
---|
147 | |
---|
148 | 3. The names of its contributors may not be used to endorse or promote |
---|
149 | products derived from this software without specific prior written |
---|
150 | permission. |
---|
151 | |
---|
152 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
153 | \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
154 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
155 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
---|
156 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
157 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
158 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
159 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
160 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
161 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
162 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.")))) |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | (if (eggdoc->html doc) (void)) |
---|