File: random-variate.html

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (144 lines) | stat: -rw-r--r-- 5,109 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Boost Random Number Library Variate Generator</title>
</head>

<body bgcolor="#FFFFFF" text="#000000">

<h1>Boost Random Number Library Variate Generator</h1>

A random variate generator is used to join a random number generator
together with a random number distribution.
Boost.Random provides a vast choice of 
<a href="random-generators.html">generators</a>
as well as
<a href="random-distributions.html">distributions</a>
.


<h2><a name="variate_generator">Class template <code>variate_generator</code></h2>

<h3>Synopsis</h3>
<pre>
#include &lt;<a href="../../boost/random/variate_generator.hpp">boost/random/variate_generator.hpp</a>&gt;

template&lt;class Engine, class Distribution&gt;
class variate_generator
{
public:
  typedef Engine engine_type;
  typedef Distribution distribution_type;
  typedef typename Distribution::result_type result_type;

  variate_generator(Engine e, Distribution d);

  result_type operator()();
  template&lt;class T&gt;
  result_type operator()(T value);
  
  engine_value_type&amp; engine();
  const engine_value_type&amp; engine() const;

  result_type min() const;
  result_type max() const;
};
</pre>

<h3>Description</h3>

Instantations of class template <code>variate_generator</code> model a
<a href="random-concepts.html#number_generator">number generator</a>. 
<p>
The argument for the template parameter <code>Engine</code> shall be
of the form U, U&, or U*, where U models a uniform random number
generator.  Then, the member <code>engine_value_type</code> names U
(not the pointer or reference to U).
<p>

Specializations of <code>variate_generator</code> satisfy the
requirements of CopyConstructible. They also satisfy the requirements
of Assignable unless the template parameter Engine is of the form U&amp;. 
<p>

The complexity of all functions specified in this section is
constant. No function described in this section except the constructor
throws an exception. 

<pre>    variate_generator(engine_type eng, distribution_type d)</pre>
<strong>Effects:</strong> Constructs a <code>variate_generator</code>
object with the associated uniform random number generator
<code>eng</code> and the associated random distribution
<code>d</code>.
<br>
<strong>Throws:</strong> If and what the copy constructor of Engine or
Distribution throws.

<pre>    result_type operator()()</pre>
<strong>Returns:</strong> <code>distribution()(e)</code>
<br>
<strong>Notes:</strong> The sequence of numbers produced by the
uniform random number generator <code>e</code>, s<sub>e</sub>, is
obtained from the sequence of numbers produced by the associated
uniform random number generator <code>eng</code>, s<sub>eng</sub>, as
follows: Consider the values of
<code>numeric_limits&lt;<em>T</em>&gt;::is_integer</code> for
<code><em>T</em></code> both <code>Distribution::input_type</code> and
<code>engine_value_type::result_type</code>.  If the values for both
types are <code>true</code>, then s<sub>e</sub> is identical to
s<sub>eng</sub>.  Otherwise, if the values for both types are
<code>false</code>, then the numbers in s<sub>eng</sub> are divided by
<code>engine().max()-engine().min()</code> to obtain the
numbers in s<sub>e</sub>.  Otherwise, if the value for
<code>engine_value_type::result_type</code> is <code>true</code> and
the value for <code>Distribution::input_type</code> is
<code>false</code>, then the numbers in s<sub>eng</sub> are divided by
<code>engine().max()-engine().min()+1</code> to obtain the
numbers in s<sub>e</sub>.  Otherwise, the mapping from s<sub>eng</sub>
to s<sub>e</sub> is implementation-defined.  In all cases, an implicit
conversion from <code>engine_value_type::result_type</code> to
<code>Distribution::input_type</code> is performed.  If such a
conversion does not exist, the program is ill-formed.

<pre>    template&lt;class T> result_type operator()(T value)</pre>
<strong>Returns:</strong> <code>distribution()(e, value)</code>.  For
the semantics of <code>e</code>, see the description of
<code>operator()()</code>.

<pre>    engine_value_type& engine()</pre>
<strong>Returns:</strong> A reference to the associated uniform random
number generator.

<pre>    const engine_value_type& engine() const</pre>
<strong>Returns:</strong> A reference to the associated uniform random
number generator.

<pre>    distribution_type& distribution()</pre>
<strong>Returns:</strong> A reference to the associated random
distribution.

<pre>    const distribution_type& distribution() const</pre>
<strong>Returns:</strong> A reference to the associated random
distribution.

<pre>    result_type min() const</pre>
<strong>Precondition:</strong> <code>distribution().min()</code> is
well-formed
<br>
<strong>Returns:</strong> <code>distribution().min()</code>

<pre>    result_type max() const</pre>
<strong>Precondition:</strong> <code>distribution().max()</code> is
well-formed
<br>
<strong>Returns:</strong> <code>distribution().max()</code>

<p>
<hr>
<a href="../../people/jens_maurer.htm">Jens Maurer</a>,
2003-10-25

</body>
</html>