|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ARandomNumberDistribution is a function object returning random numbers according to aprobability density functionp(x) or adiscrete probability distributionP(xi).
The typeD satisfiesRandomNumberDistribution if
D satisfiesCopyConstructibleD satisfiesCopyAssignableGiven
T, the type named byD::result_typeP, the type named byD::param_type, whichD that take arguments corresponding to the distribution parametersD that returns a parameter of the distributiond, a value of typeDx andy, (possibly const) values of typeDp, a (possibly const) value of typePg,g1,g2, lvalues of a type satisfyingUniformRandomBitGeneratoros, lvalue of a specialization ofstd::basic_ostreamis, lvalue of a specialization ofstd::basic_istreamThe following expressions must be valid and have their specified effects
| Expression | Type | Notes | Complexity |
|---|---|---|---|
D::result_type | T | Anarithmetic type | Compile-time |
D::param_type | P | Compile-time | |
D() | Creates a distribution indistinguishable from any other default-constructedD | Constant | |
D(p) | Creates a distribution indistinguishable fromD constructed directly from the values used to constructp | Same asp's construction | |
d.reset() | void | Resets the internal state of the distribution. The next call tooperator() ond will not depend on values produced by any engine prior toreset() | Constant |
x.param() | P | Returnsp such thatD(p).param()== p | No worse thanD(p) |
d.param(p) | void | Postcondition:d.param()== p | No worse thanD(p) |
d(g) | T | The sequence of numbers returned by successive invocations of this call with the sameg are randomly distributed according to the distribution parametrized byd.param() | Amortized constant number of invocations ofg |
d(g,p) | T | The sequence of numbers returned by successive invocations of this call with the sameg are randomly distributed according to the distribution parametrized byp | Amortized constant number of invocations ofg |
x.min() | T | The greatest lower bound on the values potentially returned byx’soperator(), as determined by the current values ofx’s parameters | Constant |
x.max() | T | The least upper bound on the values potentially returned byx’soperator(), as determined by the current values ofx’s parameters | Constant |
x == y | bool | Establishes an equivalence relation. Returnstrue ifx.param()== y.param() and future infinite sequences of values that would be generated by repeated invocations ofx(g1) andy(g2) would be equal as long asg1== g2 | Constant |
x != y | bool | !(x == y) | Constant |
os << x | Reference to the type ofos | Writes a textual representation of the distribution parameters and internal state toos. The formatting flags and fill character ofos are unchanged | |
is >> d | Reference to the type ofis | Restores the distribution parameters and internal state with data read fromis. The formatting flags ofis are unchanged. The data must have been written using a stream with the same locale,CharT andTraits stream template parameters, otherwise the behavior is undefined. If bad input is encountered,is.setstate(std::ios::failbit) is called, which may throwstd::ios_base::failure.d is unchanged in that case |
The parameters of a distribution object may be changed either permanently, by usingd.param(p) or just for the duration of a single operator() call, by usingd(g,p).
Calls to const member functions of the distribution andos<< d do not affect the sequence of numbers produced by repeatedd(g).
The following standard library components satisfyRandomNumberDistribution
(C++11) | produces integer values evenly distributed across a range (class template)[edit] |
(C++11) | produces real values evenly distributed across a range (class template)[edit] |
(C++11) | producesbool values on aBernoulli distribution (class)[edit] |
(C++11) | produces integer values on aBinomial distribution (class template) |
| produces integer values on aNegative binomial distribution (class template) | |
(C++11) | produces integer values on aGeometric distribution (class template) |
(C++11) | produces integer values on aPoisson distribution (class template) |
(C++11) | produces real values on anExponential distribution (class template) |
(C++11) | produces real values on aGamma distribution (class template) |
(C++11) | produces real values on aWeibull distribution (class template) |
(C++11) | produces real values on anExtreme value distribution (class template) |
(C++11) | produces real values on aStandard normal (Gaussian) distribution (class template) |
(C++11) | produces real values on aLognormal distribution (class template) |
(C++11) | produces real values on aChi-squared distribution (class template) |
(C++11) | produces real values on aCauchy distribution (class template) |
(C++11) | produces real values on aFisher's F-distribution (class template) |
(C++11) | produces real values on aStudent's t-distribution (class template) |
(C++11) | produces integer values on a discrete distribution (class template) |
| produces real values distributed on constant subintervals (class template) | |
| produces real values distributed on defined subintervals (class template) |