![]() |
Home | Libraries | People | FAQ | More |
boost::random::discrete_distribution
// In header: <boost/random/discrete_distribution.hpp> template<typename IntType = int, typename WeightType = double> class discrete_distribution { public: // types typedef WeightType ; typedef IntType ; // member classes/structs/unions class param_type { public: // types typedef discrete_distribution ; // construct/copy/destruct (); template<typename Iter> (Iter, Iter); (const WeightType > &); template<typename Range> (const Range &); template<typename Func> (, double, double, Func); // public member functions WeightType > () ; // friend functions template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, const param_type &); template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, const param_type &); bool (const param_type &, const param_type &); bool (const param_type &, const param_type &); }; // construct/copy/destruct (); template<typename Iter> (Iter, Iter); (WeightType >); template<typename Range> (const Range &); template<typename Func> (, double, double, Func); (const param_type &); // public member functions template<typename URNG> IntType (URNG &) ; template<typename URNG> IntType (URNG &, const param_type &) ; result_type () ; result_type () ; WeightType > () ; param_type () ; void (const param_type &); void (); // friend functions template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, const discrete_distribution &); template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, const discrete_distribution &); bool (const discrete_distribution &, const discrete_distribution &); bool (const discrete_distribution &, const discrete_distribution &); };
The class discrete_distribution
models a random distribution . It produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution.
discrete_distribution
public
construct/copy/destruct();
Creates a new
object that has discrete_distribution
and
.
template<typename Iter> (Iter first, Iter last);
Constructs a discrete_distribution
from an iterator range. If first
== last
, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution.
(WeightType > wl);
Constructs a
from a discrete_distribution
std::initializer_list
. If the initializer_list
is empty, equivalent to the default constructor. Otherwise, the values of the initializer_list
represent weights for the possible values of the distribution. For example, given the distribution
The probability of a 0 is 1/10, the probability of a 1 is 2/5, the probability of a 2 is 1/2, and no other values are possible.
template<typename Range> (const Range & range);
Constructs a discrete_distribution
from a Boost.Range range. If the range is empty, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution.
template<typename Func> ( nw, double xmin, double xmax, Func fw);
Constructs a discrete_distribution
that approximates a function. If nw is zero, equivalent to the default constructor. Otherwise, the range of the distribution is [0, nw), and the weights are found by calling fw with values evenly distributed between and
, where
.
(const param_type & param);
Constructs a discrete_distribution
from its parameters.
discrete_distribution
public member functionstemplate<typename URNG> IntType (URNG & urng) ;
Returns a value distributed according to the parameters of the discrete_distribution
.
template<typename URNG> IntType (URNG & urng, const param_type & param) ;
Returns a value distributed according to the parameters specified by param.
result_type () ;
Returns the smallest value that the distribution can produce.
result_type () ;
Returns the largest value that the distribution can produce.
WeightType > () ;
Returns a vector containing the probabilities of each value of the distribution. For example, given
the vector, p will contain {0.1, 0.4, 0.5}.
If WeightType
is integral, then the weights will be returned unchanged.
param_type () ;
Returns the parameters of the distribution.
void (const param_type & param);
Sets the parameters of the distribution.
void ();
Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset.
discrete_distribution
friend functionstemplate<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > & os, const discrete_distribution & dd);
Writes a distribution to a std::ostream
.
template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > & is, const discrete_distribution & dd);
Reads a distribution from a std::istream
bool (const discrete_distribution & lhs, const discrete_distribution & rhs);
Returns true if the two distributions will return the same sequence of values, when passed equal generators.
bool (const discrete_distribution & lhs, const discrete_distribution & rhs);
Returns true if the two distributions may return different sequences of values, when passed equal generators.