Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::random::discrete_distribution< IntType, WeightType > Class Template Reference

The class discrete_distribution models a . More...

#include <discrete_distribution.hpp>

Inheritance diagram for boost::random::discrete_distribution< IntType, WeightType >:

Classes

class  param_type
 

Public Types

typedef WeightType input_type
 
typedef IntType result_type
 

Public Member Functions

 discrete_distribution ()
 Creates a new discrete_distribution object that has $p(0) = 1$ and $p(i|i>0) = 0$. More...
 
template<class Iter >
 discrete_distribution (Iter first, Iter last)
 Constructs a discrete_distribution from an iterator range. More...
 
 discrete_distribution (std::initializer_list< WeightType > wl)
 Constructs a discrete_distribution from a std::initializer_list. More...
 
template<class Range >
 discrete_distribution (const Range &range)
 Constructs a discrete_distribution from a Boost.Range range. More...
 
template<class Func >
 discrete_distribution (std::size_t nw, double xmin, double xmax, Func fw)
 Constructs a discrete_distribution that approximates a function. More...
 
 discrete_distribution (const param_type &parm)
 Constructs a discrete_distribution from its parameters. More...
 
template<class URNG >
IntType operator() (URNG &urng) const
 Returns a value distributed according to the parameters of the discrete_distribution. More...
 
template<class URNG >
IntType operator() (URNG &urng, const param_type &parm) const
 Returns a value distributed according to the parameters specified by param. More...
 
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const
 Returns the smallest value that the distribution can produce. More...
 
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const
 Returns the largest value that the distribution can produce. More...
 
std::vector< WeightType > probabilities () const
 Returns a vector containing the probabilities of each value of the distribution. More...
 
param_type param () const
 Returns the parameters of the distribution. More...
 
void param (const param_type &parm)
 Sets the parameters of the distribution. More...
 
void reset ()
 Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset. More...
 
 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR (os, discrete_distribution, dd)
 Writes a distribution to a std::ostream. More...
 
 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR (is, discrete_distribution, dd)
 Reads a distribution from a std::istream. More...
 
 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR (discrete_distribution, lhs, rhs)
 Returns true if the two distributions will return the same sequence of values, when passed equal generators. More...
 

Detailed Description

template<class IntType = int, class WeightType = double>
class boost::random::discrete_distribution< IntType, WeightType >

The class discrete_distribution models a .

It produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution.

Member Typedef Documentation

template<class IntType = int, class WeightType = double>
typedef WeightType boost::random::discrete_distribution< IntType, WeightType >::input_type
template<class IntType = int, class WeightType = double>
typedef IntType boost::random::discrete_distribution< IntType, WeightType >::result_type

Constructor & Destructor Documentation

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( )
inline
template<class IntType = int, class WeightType = double>
template<class Iter >
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( Iter  first,
Iter  last 
)
inline

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.

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( std::initializer_list< WeightType >  wl)
inline

Constructs a discrete_distribution from a 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

discrete_distribution<> dist{1, 4, 5};

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<class IntType = int, class WeightType = double>
template<class Range >
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( const Range &  range)
inlineexplicit

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<class IntType = int, class WeightType = double>
template<class Func >
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( std::size_t  nw,
double  xmin,
double  xmax,
Func  fw 
)
inline

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 $\mbox{xmin} + \delta/2$ and $\mbox{xmax} - \delta/2$, where $\delta = (\mbox{xmax} - \mbox{xmin})/\mbox{nw}$.

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::discrete_distribution ( const param_type parm)
inlineexplicit

Constructs a discrete_distribution from its parameters.

Member Function Documentation

template<class IntType = int, class WeightType = double>
result_type min boost::random::discrete_distribution< IntType, WeightType >::BOOST_PREVENT_MACRO_SUBSTITUTION ( ) const
inline

Returns the smallest value that the distribution can produce.

template<class IntType = int, class WeightType = double>
result_type max boost::random::discrete_distribution< IntType, WeightType >::BOOST_PREVENT_MACRO_SUBSTITUTION ( ) const
inline

Returns the largest value that the distribution can produce.

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR ( discrete_distribution< IntType, WeightType >  ,
lhs  ,
rhs   
)
inline

Returns true if the two distributions will return the same sequence of values, when passed equal generators.

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR ( is  ,
discrete_distribution< IntType, WeightType >  ,
dd   
)
inline

Reads a distribution from a std::istream.

template<class IntType = int, class WeightType = double>
boost::random::discrete_distribution< IntType, WeightType >::BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR ( os  ,
discrete_distribution< IntType, WeightType >  ,
dd   
)
inline

Writes a distribution to a std::ostream.

template<class IntType = int, class WeightType = double>
template<class URNG >
IntType boost::random::discrete_distribution< IntType, WeightType >::operator() ( URNG &  urng) const
inline

Returns a value distributed according to the parameters of the discrete_distribution.

template<class IntType = int, class WeightType = double>
template<class URNG >
IntType boost::random::discrete_distribution< IntType, WeightType >::operator() ( URNG &  urng,
const param_type parm 
) const
inline

Returns a value distributed according to the parameters specified by param.

template<class IntType = int, class WeightType = double>
param_type boost::random::discrete_distribution< IntType, WeightType >::param ( ) const
inline

Returns the parameters of the distribution.

Referenced by boost::random::discrete_distribution< std::size_t, WeightType >::discrete_distribution().

template<class IntType = int, class WeightType = double>
void boost::random::discrete_distribution< IntType, WeightType >::param ( const param_type parm)
inline

Sets the parameters of the distribution.

template<class IntType = int, class WeightType = double>
std::vector<WeightType> boost::random::discrete_distribution< IntType, WeightType >::probabilities ( ) const
inline

Returns a vector containing the probabilities of each value of the distribution.

For example, given

discrete_distribution<> dist = { 1, 4, 5 };
std::vector<double> p = dist.param();

the vector, p will contain {0.1, 0.4, 0.5}.

If WeightType is integral, then the weights will be returned unchanged.

template<class IntType = int, class WeightType = double>
void boost::random::discrete_distribution< IntType, WeightType >::reset ( void  )
inline

Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset.


The documentation for this class was generated from the following file: