[12] | 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 Generator Library (Miscellaneous)</title> |
---|
| 8 | </head> |
---|
| 9 | |
---|
| 10 | <body bgcolor="#FFFFFF" text="#000000"> |
---|
| 11 | |
---|
| 12 | <h1>Random Number Generator Library --- Miscellaneous Decorators</h1> |
---|
| 13 | |
---|
| 14 | <ul> |
---|
| 15 | <li><a href="#random_number_generator">Class template |
---|
| 16 | <code>random_number_generator</code></a> |
---|
| 17 | </ul> |
---|
| 18 | |
---|
| 19 | <h2>Introduction</h2> |
---|
| 20 | |
---|
| 21 | These decorator class templates allow adaptation of the random number |
---|
| 22 | generators and distribution functions to concepts found in the C++ |
---|
| 23 | Standard Library, in particular the RandomNumberGenerator and the |
---|
| 24 | InputIterator concepts. The latter adaptation is useful, because the |
---|
| 25 | the basic random number generators do not implement the InputIterator |
---|
| 26 | requirements per se, in contrast to the distribution functions. |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | <h2><a name="synopsis">Synopsis</a> of miscellaneous decorators in |
---|
| 30 | header <code><boost/random.hpp></code></h2> |
---|
| 31 | |
---|
| 32 | <pre> |
---|
| 33 | namespace boost { |
---|
| 34 | template<class UniformRandomNumberGenerator, class IntType = long> |
---|
| 35 | class random_number_generator; |
---|
| 36 | } // namespace boost |
---|
| 37 | </pre> |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | <h2><a name="random_number_generator">Class template |
---|
| 41 | <code>random_number_generator</code></a></h2> |
---|
| 42 | |
---|
| 43 | <h3>Synopsis</h3> |
---|
| 44 | <pre> |
---|
| 45 | template<class UniformRandomNumberGenerator, class IntType = long> |
---|
| 46 | class random_number_generator |
---|
| 47 | { |
---|
| 48 | public: |
---|
| 49 | typedef UniformRandomNumberGenerator base_type; |
---|
| 50 | typedef IntType argument_type; |
---|
| 51 | typedef IntType result_type; |
---|
| 52 | random_number_generator(base_type & rng); |
---|
| 53 | result_type operator()(argument_type n); |
---|
| 54 | }; |
---|
| 55 | </pre> |
---|
| 56 | |
---|
| 57 | <h3>Description</h3> |
---|
| 58 | |
---|
| 59 | Instantiations of class template <code>random_number_generator</code> |
---|
| 60 | model a RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). |
---|
| 61 | On each invocation, it returns a uniformly distributed integer in |
---|
| 62 | the range [0..<code>n</code>). |
---|
| 63 | <p> |
---|
| 64 | The template parameter <code>IntType</code> shall denote some |
---|
| 65 | integer-like value type. |
---|
| 66 | <p> |
---|
| 67 | |
---|
| 68 | <em>Note:</em> I consider it unfortunate that the C++ Standard uses |
---|
| 69 | the name RandomNumberGenerator for something rather specific. |
---|
| 70 | |
---|
| 71 | <h3>Members</h3> |
---|
| 72 | |
---|
| 73 | <pre>random_number_generator(base_type & rng)</pre> |
---|
| 74 | |
---|
| 75 | <strong>Effects:</strong> Constructs a |
---|
| 76 | <code>random_number_generator</code> functor with the given uniform |
---|
| 77 | random number generator as the underlying source of random numbers. |
---|
| 78 | |
---|
| 79 | <pre>result_type operator()(argument_type n)</pre> |
---|
| 80 | |
---|
| 81 | <strong>Returns:</strong> The value of |
---|
| 82 | <code>uniform_int<base_type>(rng, 0, n-1)()</code>. |
---|
| 83 | |
---|
| 84 | <p> |
---|
| 85 | <hr> |
---|
| 86 | Jens Maurer, 2001-11-19 |
---|
| 87 | |
---|
| 88 | </body> |
---|
| 89 | </html> |
---|