[29] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | |
---|
| 3 | <html> |
---|
| 4 | <head> |
---|
| 5 | <meta http-equiv="Content-Language" content="en-us"> |
---|
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
---|
| 7 | |
---|
| 8 | <title>Boost Random Number Library Variate Generator</title> |
---|
| 9 | </head> |
---|
| 10 | |
---|
| 11 | <body bgcolor="#FFFFFF" text="#000000"> |
---|
| 12 | <h1>Boost Random Number Library Variate Generator</h1> |
---|
| 13 | |
---|
| 14 | <p>A random variate generator is used to join a random number generator |
---|
| 15 | together with a random number distribution. Boost.Random provides a vast |
---|
| 16 | choice of <a href="random-generators.html">generators</a> as well as |
---|
| 17 | <a href="random-distributions.html">distributions</a> .</p> |
---|
| 18 | |
---|
| 19 | <h2><a name="variate_generator" id="variate_generator">Class template |
---|
| 20 | <code>variate_generator</code></a></h2> |
---|
| 21 | |
---|
| 22 | <h3>Synopsis</h3> |
---|
| 23 | <pre> |
---|
| 24 | #include <<a href= |
---|
| 25 | "../../boost/random/variate_generator.hpp">boost/random/variate_generator.hpp</a>> |
---|
| 26 | |
---|
| 27 | template<class Engine, class Distribution> |
---|
| 28 | class variate_generator |
---|
| 29 | { |
---|
| 30 | public: |
---|
| 31 | typedef Engine engine_type; |
---|
| 32 | typedef Distribution distribution_type; |
---|
| 33 | typedef typename Distribution::result_type result_type; |
---|
| 34 | |
---|
| 35 | variate_generator(Engine e, Distribution d); |
---|
| 36 | |
---|
| 37 | result_type operator()(); |
---|
| 38 | template<class T> |
---|
| 39 | result_type operator()(T value); |
---|
| 40 | |
---|
| 41 | engine_value_type& engine(); |
---|
| 42 | const engine_value_type& engine() const; |
---|
| 43 | |
---|
| 44 | result_type min() const; |
---|
| 45 | result_type max() const; |
---|
| 46 | }; |
---|
| 47 | </pre> |
---|
| 48 | |
---|
| 49 | <h3>Description</h3> |
---|
| 50 | |
---|
| 51 | <p>Instantations of class template <code>variate_generator</code> model a |
---|
| 52 | <a href="random-concepts.html#number_generator">number generator</a>.</p> |
---|
| 53 | |
---|
| 54 | <p>The argument for the template parameter <code>Engine</code> shall be of |
---|
| 55 | the form U, U&, or U*, where U models a uniform random number |
---|
| 56 | generator. Then, the member <code>engine_value_type</code> names U (not the |
---|
| 57 | pointer or reference to U).</p> |
---|
| 58 | |
---|
| 59 | <p>Specializations of <code>variate_generator</code> satisfy the |
---|
| 60 | requirements of CopyConstructible. They also satisfy the requirements of |
---|
| 61 | Assignable unless the template parameter Engine is of the form U&.</p> |
---|
| 62 | |
---|
| 63 | <p>The complexity of all functions specified in this section is constant. |
---|
| 64 | No function described in this section except the constructor throws an |
---|
| 65 | exception.</p> |
---|
| 66 | <pre> |
---|
| 67 | variate_generator(engine_type eng, distribution_type d) |
---|
| 68 | </pre> |
---|
| 69 | |
---|
| 70 | <p><strong>Effects:</strong> Constructs a <code>variate_generator</code> |
---|
| 71 | object with the associated uniform random number generator <code>eng</code> |
---|
| 72 | and the associated random distribution <code>d</code>.<br> |
---|
| 73 | <strong>Throws:</strong> If and what the copy constructor of Engine or |
---|
| 74 | Distribution throws.</p> |
---|
| 75 | <pre> |
---|
| 76 | result_type operator()() |
---|
| 77 | </pre> |
---|
| 78 | |
---|
| 79 | <p><strong>Returns:</strong> <code>distribution()(e)</code><br> |
---|
| 80 | <strong>Notes:</strong> The sequence of numbers produced by the uniform |
---|
| 81 | random number generator <code>e</code>, s<sub>e</sub>, is obtained from the |
---|
| 82 | sequence of numbers produced by the associated uniform random number |
---|
| 83 | generator <code>eng</code>, s<sub>eng</sub>, as follows: Consider the |
---|
| 84 | values of <code>numeric_limits<<em>T</em>>::is_integer</code> for |
---|
| 85 | <code><em>T</em></code> both <code>Distribution::input_type</code> and |
---|
| 86 | <code>engine_value_type::result_type</code>. If the values for both types |
---|
| 87 | are <code>true</code>, then s<sub>e</sub> is identical to s<sub>eng</sub>. |
---|
| 88 | Otherwise, if the values for both types are <code>false</code>, then the |
---|
| 89 | numbers in s<sub>eng</sub> are divided by |
---|
| 90 | <code>engine().max()-engine().min()</code> to obtain the numbers in |
---|
| 91 | s<sub>e</sub>. Otherwise, if the value for |
---|
| 92 | <code>engine_value_type::result_type</code> is <code>true</code> and the |
---|
| 93 | value for <code>Distribution::input_type</code> is <code>false</code>, then |
---|
| 94 | the numbers in s<sub>eng</sub> are divided by |
---|
| 95 | <code>engine().max()-engine().min()+1</code> to obtain the numbers in |
---|
| 96 | s<sub>e</sub>. Otherwise, the mapping from s<sub>eng</sub> to s<sub>e</sub> |
---|
| 97 | is implementation-defined. In all cases, an implicit conversion from |
---|
| 98 | <code>engine_value_type::result_type</code> to |
---|
| 99 | <code>Distribution::input_type</code> is performed. If such a conversion |
---|
| 100 | does not exist, the program is ill-formed.</p> |
---|
| 101 | <pre> |
---|
| 102 | template<class T> result_type operator()(T value) |
---|
| 103 | </pre> |
---|
| 104 | |
---|
| 105 | <p><strong>Returns:</strong> <code>distribution()(e, value)</code>. For the |
---|
| 106 | semantics of <code>e</code>, see the description of |
---|
| 107 | <code>operator()()</code>.</p> |
---|
| 108 | <pre> |
---|
| 109 | engine_value_type& engine() |
---|
| 110 | </pre> |
---|
| 111 | |
---|
| 112 | <p><strong>Returns:</strong> A reference to the associated uniform random |
---|
| 113 | number generator.</p> |
---|
| 114 | <pre> |
---|
| 115 | const engine_value_type& engine() const |
---|
| 116 | </pre> |
---|
| 117 | |
---|
| 118 | <p><strong>Returns:</strong> A reference to the associated uniform random |
---|
| 119 | number generator.</p> |
---|
| 120 | <pre> |
---|
| 121 | distribution_type& distribution() |
---|
| 122 | </pre> |
---|
| 123 | |
---|
| 124 | <p><strong>Returns:</strong> A reference to the associated random |
---|
| 125 | distribution.</p> |
---|
| 126 | <pre> |
---|
| 127 | const distribution_type& distribution() const |
---|
| 128 | </pre> |
---|
| 129 | |
---|
| 130 | <p><strong>Returns:</strong> A reference to the associated random |
---|
| 131 | distribution.</p> |
---|
| 132 | <pre> |
---|
| 133 | result_type min() const |
---|
| 134 | </pre> |
---|
| 135 | |
---|
| 136 | <p><strong>Precondition:</strong> <code>distribution().min()</code> is |
---|
| 137 | well-formed<br> |
---|
| 138 | <strong>Returns:</strong> <code>distribution().min()</code></p> |
---|
| 139 | <pre> |
---|
| 140 | result_type max() const |
---|
| 141 | </pre> |
---|
| 142 | |
---|
| 143 | <p><strong>Precondition:</strong> <code>distribution().max()</code> is |
---|
| 144 | well-formed<br> |
---|
| 145 | <strong>Returns:</strong> <code>distribution().max()</code></p> |
---|
| 146 | <hr> |
---|
| 147 | |
---|
| 148 | <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= |
---|
| 149 | "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" |
---|
| 150 | height="31" width="88"></a></p> |
---|
| 151 | |
---|
| 152 | <p>Revised |
---|
| 153 | <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 |
---|
| 154 | December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p> |
---|
| 155 | |
---|
| 156 | <p><i>Copyright © 2003-2004 <a href= |
---|
| 157 | "../../people/jens_maurer.htm">Jens Maurer</a></i></p> |
---|
| 158 | |
---|
| 159 | <p><i>Distributed under the Boost Software License, Version 1.0. (See |
---|
| 160 | accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or |
---|
| 161 | copy at <a href= |
---|
| 162 | "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> |
---|
| 163 | </body> |
---|
| 164 | </html> |
---|