| 1 |  | 
|---|
| 2 | <html> | 
|---|
| 3 |  | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | 
|---|
| 6 |  | 
|---|
| 7 | <title>Boost Random Number Library Distributions</title> | 
|---|
| 8 | </head> | 
|---|
| 9 |  | 
|---|
| 10 | <body bgcolor="#FFFFFF" text="#000000"> | 
|---|
| 11 |  | 
|---|
| 12 | <h1>Random Number Library Distributions</h1> | 
|---|
| 13 |  | 
|---|
| 14 | <ul> | 
|---|
| 15 | <li><a href="#intro">Introduction</a> | 
|---|
| 16 | <li><a href="#synopsis">Synopsis</a> | 
|---|
| 17 | <li><a href="#uniform_smallint">Class template | 
|---|
| 18 | <code>uniform_smallint</code></a> | 
|---|
| 19 | <li><a href="#uniform_int">Class template <code>uniform_int</code></a> | 
|---|
| 20 | <li><a href="#uniform_01">Class template <code>uniform_01</code></a> | 
|---|
| 21 | <li><a href="#uniform_real">Class template | 
|---|
| 22 | <code>uniform_real</code></a> | 
|---|
| 23 | <li><a href="#bernoulli_distribution">Class template | 
|---|
| 24 | <code>bernoulli_distribution</code></a> | 
|---|
| 25 | <li><a href="#geometric_distribution">Class template | 
|---|
| 26 | <code>geometric_distribution</code></a> | 
|---|
| 27 | <li><a href="#triangle_distribution">Class template | 
|---|
| 28 | <code>triangle_distribution</code></a> | 
|---|
| 29 | <li><a href="#exponential_distribution">Class template | 
|---|
| 30 | <code>exponential_distribution</code></a> | 
|---|
| 31 | <li><a href="#normal_distribution">Class template | 
|---|
| 32 | <code>normal_distribution</code></a> | 
|---|
| 33 | <li><a href="#lognormal_distribution">Class template | 
|---|
| 34 | <code>lognormal_distribution</code></a> | 
|---|
| 35 | <li><a href="#uniform_on_sphere">Class template | 
|---|
| 36 | <code>uniform_on_sphere</code></a> | 
|---|
| 37 | </ul> | 
|---|
| 38 |  | 
|---|
| 39 | <h2><a name="intro">Introduction</a></h2> | 
|---|
| 40 |  | 
|---|
| 41 | In addition to the <a href="random-generators.html">random number | 
|---|
| 42 | generators</a>, this library provides distribution functions which map | 
|---|
| 43 | one distribution (often a uniform distribution provided by some | 
|---|
| 44 | generator) to another. | 
|---|
| 45 |  | 
|---|
| 46 | <p> | 
|---|
| 47 | Usually, there are several possible implementations of any given | 
|---|
| 48 | mapping.  Often, there is a choice between using more space, more | 
|---|
| 49 | invocations of the underlying source of random numbers, or more | 
|---|
| 50 | time-consuming arithmetic such as trigonometric functions.  This | 
|---|
| 51 | interface description does not mandate any specific implementation. | 
|---|
| 52 | However, implementations which cannot reach certain values of the | 
|---|
| 53 | specified distribution or otherwise do not converge statistically to | 
|---|
| 54 | it are not acceptable. | 
|---|
| 55 |  | 
|---|
| 56 | <p> | 
|---|
| 57 | <table border="1"> | 
|---|
| 58 | <tr><th>distribution</th><th>explanation</th><th>example</th></tr> | 
|---|
| 59 |  | 
|---|
| 60 | <tr> | 
|---|
| 61 | <td><code><a href="#uniform_smallint">uniform_smallint</a></code></td> | 
|---|
| 62 | <td>discrete uniform distribution on a small set of integers (much | 
|---|
| 63 | smaller than the range of the underlying generator)</td> | 
|---|
| 64 | <td>drawing from an urn</td> | 
|---|
| 65 | </tr> | 
|---|
| 66 |  | 
|---|
| 67 | <tr> | 
|---|
| 68 | <td><code><a href="#uniform_int">uniform_int</a></code></td> | 
|---|
| 69 | <td>discrete uniform distribution on a set of integers; the underlying | 
|---|
| 70 | generator may be called several times to gather enough randomness for | 
|---|
| 71 | the output</td> | 
|---|
| 72 | <td>drawing from an urn</td> | 
|---|
| 73 | </tr> | 
|---|
| 74 |  | 
|---|
| 75 | <tr> | 
|---|
| 76 | <td><code><a href="#uniform_01">uniform_01</a></code></td> | 
|---|
| 77 | <td>continuous uniform distribution on the range [0,1); important | 
|---|
| 78 | basis for other distributions</td> | 
|---|
| 79 | <td>-</td> | 
|---|
| 80 | </tr> | 
|---|
| 81 |  | 
|---|
| 82 | <tr> | 
|---|
| 83 | <td><code><a href="#uniform_real">uniform_real</a></code></td> | 
|---|
| 84 | <td>continuous uniform distribution on some range [min, max) of real | 
|---|
| 85 | numbers</td> | 
|---|
| 86 | <td>for the range [0, 2pi): randomly dropping a stick and measuring | 
|---|
| 87 | its angle in radiants (assuming the angle is uniformly | 
|---|
| 88 | distributed)</td> | 
|---|
| 89 | </tr> | 
|---|
| 90 |  | 
|---|
| 91 | <tr> | 
|---|
| 92 | <td><code><a href="#bernoulli_distribution">bernoulli_distribution</a></code></td> | 
|---|
| 93 | <td>Bernoulli experiment: discrete boolean valued distribution with | 
|---|
| 94 | configurable probability</td> | 
|---|
| 95 | <td>tossing a coin (p=0.5)</td> | 
|---|
| 96 | </tr> | 
|---|
| 97 |  | 
|---|
| 98 | <tr> | 
|---|
| 99 | <td><code><a href="#geometric_distribution">geometric_distribution</a></code></td> | 
|---|
| 100 | <td>measures distance between outcomes of repeated Bernoulli experiments</td> | 
|---|
| 101 | <td>throwing a die several times and counting the number of tries | 
|---|
| 102 | until a "6" appears for the first time</td> | 
|---|
| 103 | </tr> | 
|---|
| 104 |  | 
|---|
| 105 | <tr> | 
|---|
| 106 | <td><code><a href="#triangle_distribution">triangle_distribution</a></code></td> | 
|---|
| 107 | <td>?</td> | 
|---|
| 108 | <td>?</td> | 
|---|
| 109 | </tr> | 
|---|
| 110 |  | 
|---|
| 111 | <tr> | 
|---|
| 112 | <td><code><a href="#exponential_distribution">exponential_distribution</a></code></td> | 
|---|
| 113 | <td>exponential distribution</td> | 
|---|
| 114 | <td>measuring the inter-arrival time of alpha particles emitted by | 
|---|
| 115 | radioactive matter</td> | 
|---|
| 116 | </tr> | 
|---|
| 117 |  | 
|---|
| 118 | <tr> | 
|---|
| 119 | <td><code><a href="#normal_distribution">normal_distribution</a></code></td> | 
|---|
| 120 | <td>counts outcomes of (infinitely) repeated Bernoulli experiments</td> | 
|---|
| 121 | <td>tossing a coin 10000 times and counting how many front sides are shown</td> | 
|---|
| 122 | </tr> | 
|---|
| 123 |  | 
|---|
| 124 | <tr> | 
|---|
| 125 | <td><code><a href="#lognormal_distribution">lognormal_distribution</a></code></td> | 
|---|
| 126 | <td>lognormal distribution (sometimes used in simulations)</td> | 
|---|
| 127 | <td>measuring the job completion time of an assembly line worker</td> | 
|---|
| 128 | </tr> | 
|---|
| 129 |  | 
|---|
| 130 | <tr> | 
|---|
| 131 | <td><code><a href="#uniform_on_sphere">uniform_on_sphere</a></code></td> | 
|---|
| 132 | <td>uniform distribution on a unit sphere of arbitrary dimension</td> | 
|---|
| 133 | <td>choosing a random point on Earth (assumed to be a sphere) where to | 
|---|
| 134 | spend the next vacations</td> | 
|---|
| 135 | </tr> | 
|---|
| 136 |  | 
|---|
| 137 | </table> | 
|---|
| 138 |  | 
|---|
| 139 | <p> | 
|---|
| 140 |  | 
|---|
| 141 | The template parameters of the distribution functions are always in | 
|---|
| 142 | the order | 
|---|
| 143 | <ul> | 
|---|
| 144 | <li>Underlying source of random numbers | 
|---|
| 145 | <li>If applicable, return type, with a default to a reasonable type. | 
|---|
| 146 | </ul> | 
|---|
| 147 |  | 
|---|
| 148 | <p> | 
|---|
| 149 | <em>The distribution functions no longer satisfy the input iterator | 
|---|
| 150 | requirements (std:24.1.1 [lib.input.iterators]), because this is | 
|---|
| 151 | redundant given the Generator interface and imposes a run-time | 
|---|
| 152 | overhead on all users.  Moreover, a Generator interface appeals to | 
|---|
| 153 | random number generation as being more "natural".  Use an | 
|---|
| 154 | <a href="../utility/iterator_adaptors.htm">iterator adaptor</a> | 
|---|
| 155 | if you need to wrap any of the generators in an input iterator | 
|---|
| 156 | interface.</em> | 
|---|
| 157 | <p> | 
|---|
| 158 |  | 
|---|
| 159 | All of the distribution functions described below store a non-const | 
|---|
| 160 | reference to the underlying source of random numbers.  Therefore, the | 
|---|
| 161 | distribution functions are not Assignable.  However, they are | 
|---|
| 162 | CopyConstructible.  Copying a distribution function will copy the | 
|---|
| 163 | parameter values.  Furthermore, both the copy and the original will | 
|---|
| 164 | refer to the same underlying source of random numbers.  Therefore, | 
|---|
| 165 | both the copy and the original will obtain their underlying random | 
|---|
| 166 | numbers from a single sequence. | 
|---|
| 167 |  | 
|---|
| 168 | <p> | 
|---|
| 169 | In this description, I have refrained from documenting those members | 
|---|
| 170 | in detail which are already defined in the | 
|---|
| 171 | <a href="random-concepts.html">concept documentation</a>. | 
|---|
| 172 |  | 
|---|
| 173 |  | 
|---|
| 174 | <h2><a name="synopsis">Synopsis of the distributions</a> available from header | 
|---|
| 175 | <code><boost/random.hpp></code> </h2> | 
|---|
| 176 |  | 
|---|
| 177 | <pre> | 
|---|
| 178 | namespace boost { | 
|---|
| 179 |   template<class IntType = int> | 
|---|
| 180 |   class uniform_smallint; | 
|---|
| 181 |   template<class IntType = int> | 
|---|
| 182 |   class uniform_int; | 
|---|
| 183 |   template<class RealType = double> | 
|---|
| 184 |   class uniform_01; | 
|---|
| 185 |   template<class RealType = double> | 
|---|
| 186 |   class uniform_real; | 
|---|
| 187 |  | 
|---|
| 188 |   // discrete distributions | 
|---|
| 189 |   template<class RealType = double> | 
|---|
| 190 |   class bernoulli_distribution; | 
|---|
| 191 |   template<class IntType = int> | 
|---|
| 192 |   class geometric_distribution; | 
|---|
| 193 |  | 
|---|
| 194 |   // continuous distributions | 
|---|
| 195 |   template<class RealType = double> | 
|---|
| 196 |   class triangle_distribution; | 
|---|
| 197 |   template<class RealType = double> | 
|---|
| 198 |   class exponential_distribution; | 
|---|
| 199 |   template<class RealType = double> | 
|---|
| 200 |   class normal_distribution; | 
|---|
| 201 |   template<class RealType = double> | 
|---|
| 202 |   class lognormal_distribution; | 
|---|
| 203 |   template<class RealType = double, | 
|---|
| 204 |     class Cont = std::vector<RealType> > | 
|---|
| 205 |   class uniform_on_sphere; | 
|---|
| 206 | } | 
|---|
| 207 | </pre> | 
|---|
| 208 |  | 
|---|
| 209 | <h2><a name="uniform_smallint">Class template | 
|---|
| 210 | <code>uniform_smallint</code></a></h2> | 
|---|
| 211 |  | 
|---|
| 212 | <h3>Synopsis</h3> | 
|---|
| 213 |  | 
|---|
| 214 | <pre> | 
|---|
| 215 | #include <<a href="../../boost/random/uniform_smallint.hpp">boost/random/uniform_smallint.hpp</a>> | 
|---|
| 216 |  | 
|---|
| 217 | template<class IntType = int> | 
|---|
| 218 | class uniform_smallint | 
|---|
| 219 | { | 
|---|
| 220 | public: | 
|---|
| 221 |   typedef IntType input_type; | 
|---|
| 222 |   typedef IntType result_type; | 
|---|
| 223 |   static const bool has_fixed_range = false; | 
|---|
| 224 |   uniform_smallint(IntType min, IntType max); | 
|---|
| 225 |   result_type min() const; | 
|---|
| 226 |   result_type max() const; | 
|---|
| 227 |   void reset(); | 
|---|
| 228 |   template<class UniformRandomNumberGenerator> | 
|---|
| 229 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 230 | }; | 
|---|
| 231 | </pre> | 
|---|
| 232 |  | 
|---|
| 233 | <h3>Description</h3> | 
|---|
| 234 |  | 
|---|
| 235 | The distribution function <code>uniform_smallint</code> models a | 
|---|
| 236 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 237 | On each invocation, it returns a random integer value | 
|---|
| 238 | uniformly distributed in the set of integer numbers {min, min+1, | 
|---|
| 239 | min+2, ..., max}.  It assumes that the desired range (max-min+1) is | 
|---|
| 240 | small compared to the range of the underlying source of random | 
|---|
| 241 | numbers and thus makes no attempt to limit quantization errors. | 
|---|
| 242 | <p> | 
|---|
| 243 | Let r<sub>out</sub>=(max-min+1) the desired range of integer numbers, | 
|---|
| 244 | and let r<sub>base</sub> be the range of the underlying source of | 
|---|
| 245 | random numbers.  Then, for the uniform distribution, the theoretical | 
|---|
| 246 | probability for any number i in the range r<sub>out</sub> will be | 
|---|
| 247 | p<sub>out</sub>(i) = 1/r<sub>out</sub>.  Likewise, assume a uniform | 
|---|
| 248 | distribution on r<sub>base</sub> for the underlying source of random | 
|---|
| 249 | numbers, i.e. p<sub>base</sub>(i) = 1/r<sub>base</sub>.  Let | 
|---|
| 250 | p<sub>out_s</sub>(i) denote the random distribution generated by | 
|---|
| 251 | <code>uniform_smallint</code>.  Then the sum over all i in | 
|---|
| 252 | r<sub>out</sub> of (p<sub>out_s</sub>(i)/p<sub>out</sub>(i) | 
|---|
| 253 | -1)<sup>2</sup> shall not exceed | 
|---|
| 254 | r<sub>out</sub>/r<sub>base</sub><sup>2</sup> (r<sub>base</sub> mod | 
|---|
| 255 | r<sub>out</sub>)(r<sub>out</sub> - r<sub>base</sub> mod | 
|---|
| 256 | r<sub>out</sub>). | 
|---|
| 257 | <p> | 
|---|
| 258 |  | 
|---|
| 259 | The template parameter <code>IntType</code> shall denote an | 
|---|
| 260 | integer-like value type. | 
|---|
| 261 |  | 
|---|
| 262 | <p> | 
|---|
| 263 | <em>Note:</em> The property above is the square sum of the relative | 
|---|
| 264 | differences in probabilities between the desired uniform distribution | 
|---|
| 265 | p<sub>out</sub>(i) and the generated distribution | 
|---|
| 266 | p<sub>out_s</sub>(i).  The property can be fulfilled with the | 
|---|
| 267 | calculation (base_rng mod r<sub>out</sub>), as follows: Let r = | 
|---|
| 268 | r<sub>base</sub> mod r<sub>out</sub>.  The base distribution on | 
|---|
| 269 | r<sub>base</sub> is folded onto the range r<sub>out</sub>.  The | 
|---|
| 270 | numbers i < r have assigned (r<sub>base</sub> div | 
|---|
| 271 | r<sub>out</sub>)+1 numbers of the base distribution, the rest has only | 
|---|
| 272 | (r<sub>base</sub> div r<sub>out</sub>).  Therefore, | 
|---|
| 273 | p<sub>out_s</sub>(i) = ((r<sub>base</sub> div r<sub>out</sub>)+1) / | 
|---|
| 274 | r<sub>base</sub> for i < r and p<sub>out_s</sub>(i) = | 
|---|
| 275 | (r<sub>base</sub> div r<sub>out</sub>)/r<sub>base</sub> otherwise. | 
|---|
| 276 | Substituting this in the above sum formula leads to the desired | 
|---|
| 277 | result. | 
|---|
| 278 | <p> | 
|---|
| 279 | <em>Note:</em> The upper bound for (r<sub>base</sub> mod r<sub>out</sub>)(r<sub>out</sub> - r<sub>base</sub> | 
|---|
| 280 | mod r<sub>out</sub>) is r<sub>out</sub><sup>2</sup>/4.  Regarding the upper bound for the square | 
|---|
| 281 | sum of the relative quantization error of r<sub>out</sub><sup>3</sup>/(4*r<sub>base</sub><sup>2</sup>), it | 
|---|
| 282 | seems wise to either choose r<sub>base</sub> so that r<sub>base</sub> > 10*r<sub>out</sub><sup>2</sup> or | 
|---|
| 283 | ensure that r<sub>base</sub> is divisible by r<sub>out</sub>. | 
|---|
| 284 |  | 
|---|
| 285 |  | 
|---|
| 286 | <h3>Members</h3> | 
|---|
| 287 |  | 
|---|
| 288 | <pre>uniform_smallint(IntType min, IntType max)</pre> | 
|---|
| 289 |  | 
|---|
| 290 | <strong>Effects:</strong> Constructs a <code>uniform_smallint</code> | 
|---|
| 291 | functor. <code>min</code> and <code>max</code> are the lower and upper | 
|---|
| 292 | bounds of the output range, respectively. | 
|---|
| 293 |  | 
|---|
| 294 |  | 
|---|
| 295 | <h2><a name="uniform_int">Class template <code>uniform_int</code></a></h2> | 
|---|
| 296 |  | 
|---|
| 297 | <h3>Synopsis</h3> | 
|---|
| 298 |  | 
|---|
| 299 | <pre> | 
|---|
| 300 | #include <<a href="../../boost/random/uniform_int.hpp">boost/random/uniform_int.hpp</a>> | 
|---|
| 301 |  | 
|---|
| 302 | template<class IntType = int> | 
|---|
| 303 | class uniform_int | 
|---|
| 304 | { | 
|---|
| 305 | public: | 
|---|
| 306 |   typedef IntType input_type; | 
|---|
| 307 |   typedef IntType result_type; | 
|---|
| 308 |   static const bool has_fixed_range = false; | 
|---|
| 309 |   explicit uniform_int(IntType min = 0, IntType max = 9); | 
|---|
| 310 |   result_type min() const; | 
|---|
| 311 |   result_type max() const; | 
|---|
| 312 |   void reset(); | 
|---|
| 313 |   template<class UniformRandomNumberGenerator> | 
|---|
| 314 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 315 |   template<class UniformRandomNumberGenerator> | 
|---|
| 316 |   result_type operator()(UniformRandomNumberGenerator& urng, result_type n); | 
|---|
| 317 | }; | 
|---|
| 318 | </pre> | 
|---|
| 319 |  | 
|---|
| 320 | <h3>Description</h3> | 
|---|
| 321 |  | 
|---|
| 322 | The distribution function <code>uniform_int</code> models a | 
|---|
| 323 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 324 | On each invocation, it returns a random integer | 
|---|
| 325 | value uniformly distributed in the set of integer numbers | 
|---|
| 326 | {min, min+1, min+2, ..., max}. | 
|---|
| 327 | <p> | 
|---|
| 328 |  | 
|---|
| 329 | The template parameter <code>IntType</code> shall denote an | 
|---|
| 330 | integer-like value type. | 
|---|
| 331 |  | 
|---|
| 332 | <h3>Members</h3> | 
|---|
| 333 |  | 
|---|
| 334 | <pre>    uniform_int(IntType min = 0, IntType max = 9)</pre> | 
|---|
| 335 | <strong>Requires:</strong> min <= max | 
|---|
| 336 | <br> | 
|---|
| 337 | <strong>Effects:</strong> Constructs a <code>uniform_int</code> | 
|---|
| 338 | object.  <code>min</code> and <code>max</code> are the parameters of | 
|---|
| 339 | the distribution. | 
|---|
| 340 |  | 
|---|
| 341 | <pre>    result_type min() const</pre> | 
|---|
| 342 | <strong>Returns:</strong> The "min" parameter of the distribution. | 
|---|
| 343 |  | 
|---|
| 344 | <pre>    result_type max() const</pre> | 
|---|
| 345 | <strong>Returns:</strong> The "max" parameter of the distribution. | 
|---|
| 346 |  | 
|---|
| 347 | <pre>    result_type operator()(UniformRandomNumberGenerator& urng, result_type  | 
|---|
| 348 | n)</pre> | 
|---|
| 349 | <strong>Returns:</strong> A uniform random number x in the range 0 | 
|---|
| 350 | <= x < n.  <em>[Note: This allows a | 
|---|
| 351 | <code>variate_generator</code> object with a <code>uniform_int</code> | 
|---|
| 352 | distribution to be used with std::random_shuffe, see | 
|---|
| 353 | [lib.alg.random.shuffle]. ]</em> | 
|---|
| 354 |  | 
|---|
| 355 |  | 
|---|
| 356 | <h2><a name="uniform_01">Class template <code>uniform_01</code></a></h2> | 
|---|
| 357 |  | 
|---|
| 358 | <h3>Synopsis</h3> | 
|---|
| 359 |  | 
|---|
| 360 | <pre> | 
|---|
| 361 | #include <<a href="../../boost/random/uniform_01.hpp">boost/random/uniform_01.hpp</a>> | 
|---|
| 362 |  | 
|---|
| 363 | template<class UniformRandomNumberGenerator, class RealType = double> | 
|---|
| 364 | class uniform_01 | 
|---|
| 365 | { | 
|---|
| 366 | public: | 
|---|
| 367 |   typedef UniformRandomNumberGenerator base_type; | 
|---|
| 368 |   typedef RealType result_type; | 
|---|
| 369 |   static const bool has_fixed_range = false; | 
|---|
| 370 |   explicit uniform_01(base_type & rng); | 
|---|
| 371 |   result_type operator()(); | 
|---|
| 372 |   result_type min() const; | 
|---|
| 373 |   result_type max() const; | 
|---|
| 374 | }; | 
|---|
| 375 | </pre> | 
|---|
| 376 |  | 
|---|
| 377 | <h3>Description</h3> | 
|---|
| 378 |  | 
|---|
| 379 | The distribution function <code>uniform_01</code> models a | 
|---|
| 380 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 381 | On each invocation, it returns a random floating-point value uniformly | 
|---|
| 382 | distributed in the range [0..1). | 
|---|
| 383 |  | 
|---|
| 384 | The value is computed using | 
|---|
| 385 | <code>std::numeric_limits<RealType>::digits</code> random binary | 
|---|
| 386 | digits, i.e. the mantissa of the floating-point value is completely | 
|---|
| 387 | filled with random bits. [<em>Note:</em> Should this be configurable?] | 
|---|
| 388 |  | 
|---|
| 389 | <p> | 
|---|
| 390 | The template parameter <code>RealType</code> shall denote a float-like | 
|---|
| 391 | value type with support for binary operators +, -, and /.  It must be | 
|---|
| 392 | large enough to hold floating-point numbers of value | 
|---|
| 393 | <code>rng.max()-rng.min()+1</code>. | 
|---|
| 394 | <p> | 
|---|
| 395 | <code>base_type::result_type</code> must be a number-like value type, | 
|---|
| 396 | it must support <code>static_cast<></code> to | 
|---|
| 397 | <code>RealType</code> and binary operator -. | 
|---|
| 398 |  | 
|---|
| 399 | <p> | 
|---|
| 400 |  | 
|---|
| 401 | <em>Note:</em> The current implementation is buggy, because it may not | 
|---|
| 402 | fill all of the mantissa with random bits.  I'm unsure how to fill a | 
|---|
| 403 | (to-be-invented) <code>boost::bigfloat</code> class with random bits | 
|---|
| 404 | efficiently.  It's probably time for a traits class. | 
|---|
| 405 |  | 
|---|
| 406 | <h3>Members</h3> | 
|---|
| 407 |  | 
|---|
| 408 | <pre>explicit uniform_01(base_type & rng)</pre> | 
|---|
| 409 |  | 
|---|
| 410 | <strong>Effects:</strong> Constructs a <code>uniform_01</code> functor | 
|---|
| 411 | with the given uniform random number generator as the underlying | 
|---|
| 412 | source of random numbers. | 
|---|
| 413 |  | 
|---|
| 414 |  | 
|---|
| 415 | <h2><a name="uniform_real">Class template <code>uniform_real</code></a></h2> | 
|---|
| 416 |  | 
|---|
| 417 | <h3>Synopsis</h3> | 
|---|
| 418 |  | 
|---|
| 419 | <pre> | 
|---|
| 420 | #include <<a href="../../boost/random/uniform_real.hpp">boost/random/uniform_real.hpp</a>> | 
|---|
| 421 |  | 
|---|
| 422 | template<class RealType = double> | 
|---|
| 423 | class uniform_real | 
|---|
| 424 | { | 
|---|
| 425 | public: | 
|---|
| 426 |   typedef RealType input_type; | 
|---|
| 427 |   typedef RealType result_type; | 
|---|
| 428 |   static const bool has_fixed_range = false; | 
|---|
| 429 |   uniform_real(RealType min = RealType(0), RealType max = RealType(1)); | 
|---|
| 430 |   result_type min() const; | 
|---|
| 431 |   result_type max() const; | 
|---|
| 432 |   void reset(); | 
|---|
| 433 |   template<class UniformRandomNumberGenerator> | 
|---|
| 434 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 435 | }; | 
|---|
| 436 | </pre> | 
|---|
| 437 |  | 
|---|
| 438 | <h3>Description</h3> | 
|---|
| 439 |  | 
|---|
| 440 | The distribution function <code>uniform_real</code> models a | 
|---|
| 441 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 442 | On each invocation, it returns a random floating-point | 
|---|
| 443 | value uniformly distributed in the range [min..max). The value is | 
|---|
| 444 | computed using | 
|---|
| 445 | <code>std::numeric_limits<RealType>::digits</code> random binary | 
|---|
| 446 | digits, i.e. the mantissa of the floating-point value is completely | 
|---|
| 447 | filled with random bits. | 
|---|
| 448 | <p> | 
|---|
| 449 |  | 
|---|
| 450 | <em>Note:</em> The current implementation is buggy, because it may not | 
|---|
| 451 | fill all of the mantissa with random bits. | 
|---|
| 452 |  | 
|---|
| 453 |  | 
|---|
| 454 | <h3>Members</h3> | 
|---|
| 455 |  | 
|---|
| 456 | <pre>    uniform_real(RealType min = RealType(0), RealType max = RealType(1))</pre> | 
|---|
| 457 | <strong>Requires:</strong> min <= max | 
|---|
| 458 | <br> | 
|---|
| 459 | <strong>Effects:</strong> Constructs a | 
|---|
| 460 | <code>uniform_real</code> object; <code>min</code> and | 
|---|
| 461 | <code>max</code> are the parameters of the distribution. | 
|---|
| 462 |  | 
|---|
| 463 | <pre>    result_type min() const</pre> | 
|---|
| 464 | <strong>Returns:</strong> The "min" parameter of the distribution. | 
|---|
| 465 |  | 
|---|
| 466 | <pre>    result_type max() const</pre> | 
|---|
| 467 | <strong>Returns:</strong> The "max" parameter of the distribution. | 
|---|
| 468 |  | 
|---|
| 469 |  | 
|---|
| 470 | <h2><a name="bernoulli_distribution">Class template | 
|---|
| 471 | <code>bernoulli_distribution</code></a></h2> | 
|---|
| 472 |  | 
|---|
| 473 | <h3>Synopsis</h3> | 
|---|
| 474 |  | 
|---|
| 475 | <pre> | 
|---|
| 476 | #include <<a href="../../boost/random/bernoulli_distribution.hpp">boost/random/bernoulli_distribution.hpp</a>> | 
|---|
| 477 |  | 
|---|
| 478 | template<class RealType = double> | 
|---|
| 479 | class bernoulli_distribution | 
|---|
| 480 | { | 
|---|
| 481 | public: | 
|---|
| 482 |   typedef int input_type; | 
|---|
| 483 |   typedef bool result_type; | 
|---|
| 484 |  | 
|---|
| 485 |   explicit bernoulli_distribution(const RealType& p = RealType(0.5)); | 
|---|
| 486 |   RealType p() const; | 
|---|
| 487 |   void reset(); | 
|---|
| 488 |   template<class UniformRandomNumberGenerator> | 
|---|
| 489 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 490 | }; | 
|---|
| 491 | </pre> | 
|---|
| 492 |  | 
|---|
| 493 | <h3>Description</h3> | 
|---|
| 494 |  | 
|---|
| 495 | Instantiations of class template <code>bernoulli_distribution</code> | 
|---|
| 496 | model a <a href="random-concepts.html#random-dist">random | 
|---|
| 497 | distribution</a>.  Such a random distribution produces | 
|---|
| 498 | <code>bool</code> values distributed with probabilities P(true) = p | 
|---|
| 499 | and P(false) = 1-p.  p is the parameter of the distribution. | 
|---|
| 500 |  | 
|---|
| 501 | <h3>Members</h3> | 
|---|
| 502 |  | 
|---|
| 503 | <pre>    bernoulli_distribution(const RealType& p = RealType(0.5))</pre> | 
|---|
| 504 |  | 
|---|
| 505 | <strong>Requires:</strong> 0 <= p <= 1 | 
|---|
| 506 | <br> | 
|---|
| 507 | <strong>Effects:</strong> Constructs a | 
|---|
| 508 | <code>bernoulli_distribution</code> object.  <code>p</code> is the | 
|---|
| 509 | parameter of the distribution. | 
|---|
| 510 |  | 
|---|
| 511 | <pre>    RealType p() const</pre> | 
|---|
| 512 | <strong>Returns:</strong> The "p" parameter of the distribution. | 
|---|
| 513 |  | 
|---|
| 514 |  | 
|---|
| 515 | <h2><a name="geometric_distribution">Class template | 
|---|
| 516 | <code>geometric_distribution</code></a></h2> | 
|---|
| 517 |  | 
|---|
| 518 | <h3>Synopsis</h3> | 
|---|
| 519 | <pre> | 
|---|
| 520 | #include <<a href="../../boost/random/geometric_distribution.hpp">boost/random/geometric_distribution.hpp</a>> | 
|---|
| 521 |  | 
|---|
| 522 | template<class UniformRandomNumberGenerator, class IntType = int> | 
|---|
| 523 | class geometric_distribution | 
|---|
| 524 | { | 
|---|
| 525 | public: | 
|---|
| 526 |   typedef RealType input_type; | 
|---|
| 527 |   typedef IntType result_type; | 
|---|
| 528 |  | 
|---|
| 529 |   explicit geometric_distribution(const RealType& p = RealType(0.5)); | 
|---|
| 530 |   RealType p() const; | 
|---|
| 531 |   void reset(); | 
|---|
| 532 |   template<class UniformRandomNumberGenerator> | 
|---|
| 533 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 534 | }; | 
|---|
| 535 | </pre> | 
|---|
| 536 |  | 
|---|
| 537 |  | 
|---|
| 538 | <h3>Description</h3> | 
|---|
| 539 |  | 
|---|
| 540 | Instantiations of class template <code>geometric_distribution</code> | 
|---|
| 541 | model a | 
|---|
| 542 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 543 | A <code>geometric_distribution</code> random distribution produces | 
|---|
| 544 | integer values <em>i</em> >= 1 with p(i) = (1-p) * p<sup>i-1</sup>. | 
|---|
| 545 | p is the parameter of the distribution. | 
|---|
| 546 |  | 
|---|
| 547 |  | 
|---|
| 548 | <h3>Members</h3> | 
|---|
| 549 |  | 
|---|
| 550 | <pre>    geometric_distribution(const RealType& p = RealType(0.5))</pre> | 
|---|
| 551 |  | 
|---|
| 552 | <strong>Requires:</strong> 0 < p < 1 | 
|---|
| 553 | <br> | 
|---|
| 554 | <strong>Effects:</strong> Constructs a | 
|---|
| 555 | <code>geometric_distribution</code> object; <code>p</code> is the | 
|---|
| 556 | parameter of the distribution. | 
|---|
| 557 |  | 
|---|
| 558 | <pre>   RealType p() const</pre> | 
|---|
| 559 | <strong>Returns:</strong> The "p" parameter of the distribution. | 
|---|
| 560 |  | 
|---|
| 561 |  | 
|---|
| 562 | <h2><a name="triangle_distribution">Class template | 
|---|
| 563 | <code>triangle_distribution</code></a></h2> | 
|---|
| 564 |  | 
|---|
| 565 | <h3>Synopsis</h3> | 
|---|
| 566 | <pre> | 
|---|
| 567 | #include <<a href="../../boost/random/triangle_distribution.hpp">boost/random/triangle_distribution.hpp</a>> | 
|---|
| 568 |  | 
|---|
| 569 | template<class RealType = double> | 
|---|
| 570 | class triangle_distribution | 
|---|
| 571 | { | 
|---|
| 572 | public: | 
|---|
| 573 |   typedef RealType input_type; | 
|---|
| 574 |   typedef RealType result_type; | 
|---|
| 575 |   triangle_distribution(result_type a, result_type b, result_type c); | 
|---|
| 576 |   result_type a() const; | 
|---|
| 577 |   result_type b() const; | 
|---|
| 578 |   result_type c() const; | 
|---|
| 579 |   void reset(); | 
|---|
| 580 |   template<class UniformRandomNumberGenerator> | 
|---|
| 581 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 582 | }; | 
|---|
| 583 | </pre> | 
|---|
| 584 |  | 
|---|
| 585 | <h3>Description</h3> | 
|---|
| 586 |  | 
|---|
| 587 | Instantiations of class template <code>triangle_distribution</code> | 
|---|
| 588 | model a <a href="random-concepts.html#random-dist">random | 
|---|
| 589 | distribution</a>.  The returned floating-point values <code>x</code> | 
|---|
| 590 | satisfy <code>a <= x <= c</code>; <code>x</code> has a triangle | 
|---|
| 591 | distribution, where <code>b</code> is the most probable value for | 
|---|
| 592 | <code>x</code>. | 
|---|
| 593 |  | 
|---|
| 594 | <h3>Members</h3> | 
|---|
| 595 |  | 
|---|
| 596 | <pre>triangle_distribution(result_type a, result_type b, result_type c)</pre> | 
|---|
| 597 |  | 
|---|
| 598 | <strong>Effects:</strong> Constructs a | 
|---|
| 599 | <code>triangle_distribution</code> functor. <code>a, b, c</code> are | 
|---|
| 600 | the parameters for the distribution. | 
|---|
| 601 | <p> | 
|---|
| 602 |  | 
|---|
| 603 |  | 
|---|
| 604 | <h2><a name="exponential_distribution">Class template | 
|---|
| 605 | <code>exponential_distribution</code></a></h2> | 
|---|
| 606 |  | 
|---|
| 607 | <h3>Synopsis</h3> | 
|---|
| 608 | <pre> | 
|---|
| 609 | #include <<a href="../../boost/random/exponential_distribution.hpp">boost/random/exponential_distribution.hpp</a>> | 
|---|
| 610 |  | 
|---|
| 611 | template<class RealType = double> | 
|---|
| 612 | class exponential_distribution | 
|---|
| 613 | { | 
|---|
| 614 | public: | 
|---|
| 615 |   typedef RealType input_type; | 
|---|
| 616 |   typedef RealType result_type; | 
|---|
| 617 |   explicit exponential_distribution(const result_type& lambda); | 
|---|
| 618 |   RealType lambda() const; | 
|---|
| 619 |   void reset(); | 
|---|
| 620 |   template<class UniformRandomNumberGenerator> | 
|---|
| 621 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 622 | }; | 
|---|
| 623 | </pre> | 
|---|
| 624 |  | 
|---|
| 625 | <h3>Description</h3> | 
|---|
| 626 |  | 
|---|
| 627 | Instantiations of class template <code>exponential_distribution</code> | 
|---|
| 628 | model a <a href="random-concepts.html#random-dist">random | 
|---|
| 629 | distribution</a>.  Such a distribution produces random numbers x > | 
|---|
| 630 | 0 distributed with probability density function p(x) = lambda * | 
|---|
| 631 | exp(-lambda * x), where lambda is the parameter of the distribution. | 
|---|
| 632 |  | 
|---|
| 633 | <h3>Members</h3> | 
|---|
| 634 |  | 
|---|
| 635 | <pre>    exponential_distribution(const result_type& lambda = result_type(1))</pre> | 
|---|
| 636 | <strong>Requires:</strong> lambda > 0 | 
|---|
| 637 | <br> | 
|---|
| 638 | <strong>Effects:</strong> Constructs an | 
|---|
| 639 | <code>exponential_distribution</code> object with <code>rng</code> as | 
|---|
| 640 | the reference to the underlying source of random | 
|---|
| 641 | numbers. <code>lambda</code> is the parameter for the distribution. | 
|---|
| 642 |  | 
|---|
| 643 | <pre>    RealType lambda() const</pre> | 
|---|
| 644 | <strong>Returns:</strong> The "lambda" parameter of the distribution. | 
|---|
| 645 |  | 
|---|
| 646 |  | 
|---|
| 647 | <h2><a name="normal_distribution">Class template | 
|---|
| 648 | <code>normal_distribution</code></a></h2> | 
|---|
| 649 |  | 
|---|
| 650 | <h3>Synopsis</h3> | 
|---|
| 651 |  | 
|---|
| 652 | <pre> | 
|---|
| 653 | #include <<a href="../../boost/random/normal_distribution.hpp">boost/random/normal_distribution.hpp</a>> | 
|---|
| 654 |  | 
|---|
| 655 | template<class RealType = double> | 
|---|
| 656 | class normal_distribution | 
|---|
| 657 | { | 
|---|
| 658 | public: | 
|---|
| 659 |   typedef RealType input_type; | 
|---|
| 660 |   typedef RealType result_type; | 
|---|
| 661 |   explicit normal_distribution(const result_type& mean = 0, | 
|---|
| 662 |                                const result_type& sigma = 1); | 
|---|
| 663 |   RealType mean() const; | 
|---|
| 664 |   RealType sigma() const; | 
|---|
| 665 |   void reset(); | 
|---|
| 666 |   template<class UniformRandomNumberGenerator> | 
|---|
| 667 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 668 | }; | 
|---|
| 669 | </pre> | 
|---|
| 670 |  | 
|---|
| 671 | <h3>Description</h3> | 
|---|
| 672 |  | 
|---|
| 673 | Instantiations of class template <code>normal_distribution</code> | 
|---|
| 674 | model a <a href="random-concepts.html#random-dist">random | 
|---|
| 675 | distribution</a>.  Such a distribution produces random numbers x | 
|---|
| 676 | distributed with probability density function p(x) = | 
|---|
| 677 | 1/sqrt(2*pi*sigma) * exp(- (x-mean)<sup>2</sup> / | 
|---|
| 678 | (2*sigma<sup>2</sup>) ), where mean and sigma are the parameters of | 
|---|
| 679 | the distribution. | 
|---|
| 680 |  | 
|---|
| 681 |  | 
|---|
| 682 | <h3>Members</h3> | 
|---|
| 683 |  | 
|---|
| 684 | <pre> | 
|---|
| 685 |     explicit normal_distribution(const result_type& mean = 0, | 
|---|
| 686 |                                  const result_type& sigma = 1); | 
|---|
| 687 | </pre> | 
|---|
| 688 |  | 
|---|
| 689 | <strong>Requires:</strong> sigma > 0 | 
|---|
| 690 | <br> | 
|---|
| 691 | <strong>Effects:</strong> Constructs a | 
|---|
| 692 | <code>normal_distribution</code> object; <code>mean</code> and | 
|---|
| 693 | <code>sigma</code> are the parameters for the distribution. | 
|---|
| 694 |  | 
|---|
| 695 | <pre>    RealType mean() const</pre> | 
|---|
| 696 | <strong>Returns:</strong> The "mean" parameter of the distribution. | 
|---|
| 697 |  | 
|---|
| 698 | <pre>    RealType sigma() const</pre> | 
|---|
| 699 | <strong>Returns:</strong> The "sigma" parameter of the distribution. | 
|---|
| 700 |  | 
|---|
| 701 |  | 
|---|
| 702 | <h2><a name="lognormal_distribution">Class template | 
|---|
| 703 | <code>lognormal_distribution</code></a></h2> | 
|---|
| 704 |  | 
|---|
| 705 | <h3>Synopsis</h3> | 
|---|
| 706 |  | 
|---|
| 707 | <pre> | 
|---|
| 708 | #include <<a href="../../boost/random/lognormal_distribution.hpp">boost/random/lognormal_distribution.hpp</a>> | 
|---|
| 709 |  | 
|---|
| 710 | template<class RealType = double> | 
|---|
| 711 | class lognormal_distribution | 
|---|
| 712 | { | 
|---|
| 713 | public: | 
|---|
| 714 |   typedef typename normal_distribution<RealType>::input_type | 
|---|
| 715 |   typedef RealType result_type; | 
|---|
| 716 |   explicit lognormal_distribution(const result_type& mean = 1.0, | 
|---|
| 717 |                                   const result_type& sigma = 1.0); | 
|---|
| 718 |   RealType& mean() const; | 
|---|
| 719 |   RealType& sigma() const;                                  | 
|---|
| 720 |   void reset(); | 
|---|
| 721 |   template<class UniformRandomNumberGenerator> | 
|---|
| 722 |   result_type operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 723 | }; | 
|---|
| 724 | </pre> | 
|---|
| 725 |  | 
|---|
| 726 | <h3>Description</h3> | 
|---|
| 727 |  | 
|---|
| 728 | Instantiations of class template <code>lognormal_distribution</code> | 
|---|
| 729 | model a <a href="random-concepts.html#random-dist">random | 
|---|
| 730 | distribution</a>.  Such a distribution produces random numbers | 
|---|
| 731 | with p(x) = 1/(x * normal_sigma * sqrt(2*pi)) * exp( | 
|---|
| 732 | -(log(x)-normal_mean)<sup>2</sup> / (2*normal_sigma<sup>2</sup>) ) | 
|---|
| 733 | for x > 0, | 
|---|
| 734 | where normal_mean = log(mean<sup>2</sup>/sqrt(sigma<sup>2</sup> | 
|---|
| 735 | + mean<sup>2</sup>)) | 
|---|
| 736 | and normal_sigma = sqrt(log(1 + sigma<sup>2</sup>/mean<sup>2</sup>)). | 
|---|
| 737 |  | 
|---|
| 738 |  | 
|---|
| 739 | <h3>Members</h3> | 
|---|
| 740 |  | 
|---|
| 741 | <pre>lognormal_distribution(const result_type& mean, | 
|---|
| 742 |                        const result_type& sigma)</pre> | 
|---|
| 743 |  | 
|---|
| 744 | <strong>Effects:</strong> Constructs a | 
|---|
| 745 | <code>lognormal_distribution</code> functor. <code>mean</code> and | 
|---|
| 746 | <code>sigma</code> are the mean and standard deviation of the | 
|---|
| 747 | lognormal distribution. | 
|---|
| 748 | <p> | 
|---|
| 749 |  | 
|---|
| 750 |  | 
|---|
| 751 | <h2><a name="uniform_on_sphere">Class template | 
|---|
| 752 | <code>uniform_on_sphere</code></a></h2> | 
|---|
| 753 |  | 
|---|
| 754 | <h3>Synopsis</h3> | 
|---|
| 755 |  | 
|---|
| 756 | <pre> | 
|---|
| 757 | #include <<a href="../../boost/random/uniform_on_sphere.hpp">boost/random/uniform_on_sphere.hpp</a>> | 
|---|
| 758 |  | 
|---|
| 759 | template<class RealType = double, | 
|---|
| 760 |   class Cont = std::vector<RealType> > | 
|---|
| 761 | class uniform_on_sphere | 
|---|
| 762 | { | 
|---|
| 763 | public: | 
|---|
| 764 |   typedef RealType input_type; | 
|---|
| 765 |   typedef Cont result_type; | 
|---|
| 766 |   explicit uniform_on_sphere(int dim = 2); | 
|---|
| 767 |   void reset(); | 
|---|
| 768 |   template<class UniformRandomNumberGenerator> | 
|---|
| 769 |   const result_type & operator()(UniformRandomNumberGenerator& urng); | 
|---|
| 770 | }; | 
|---|
| 771 | </pre> | 
|---|
| 772 |  | 
|---|
| 773 | <h3>Description</h3> | 
|---|
| 774 |  | 
|---|
| 775 | Instantiations of class template <code>uniform_on_sphere</code> model a | 
|---|
| 776 | <a href="random-concepts.html#random-dist">random distribution</a>. | 
|---|
| 777 | Such a distribution produces random numbers uniformly distributed on | 
|---|
| 778 | the unit sphere of arbitrary dimension <code>dim</code>.  The | 
|---|
| 779 | <code>Cont</code> template parameter must be a STL-like container type | 
|---|
| 780 | with <code>begin</code> and <code>end</code> operations returning | 
|---|
| 781 | non-const ForwardIterators of type <code>Cont::iterator</code>. | 
|---|
| 782 |  | 
|---|
| 783 | <h3>Members</h3> | 
|---|
| 784 |  | 
|---|
| 785 | <pre>explicit uniform_on_sphere(int dim = 2)</pre> | 
|---|
| 786 |  | 
|---|
| 787 | <strong>Effects:</strong> Constructs a <code>uniform_on_sphere</code> | 
|---|
| 788 | functor. <code>dim</code> is the dimension of the sphere. | 
|---|
| 789 | <p> | 
|---|
| 790 |  | 
|---|
| 791 | <p> | 
|---|
| 792 | <hr> | 
|---|
| 793 | Jens Maurer, 2003-10-25 | 
|---|
| 794 |  | 
|---|
| 795 | </body> | 
|---|
| 796 | </html> | 
|---|