Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template discrete_distribution

boost::random::discrete_distribution

Synopsis

// In header: <boost/random/discrete_distribution.hpp>

template<typename IntType, typename WeightType> 
class discrete_distribution {
public:
  // types
  typedef  ; 
  typedef     ;

  // member classes/structs/unions

  class param_type {
  public:
    // types
    typedef discrete_distribution ;

    // construct/copy/destruct
    ();
    template<typename Iter> (, );
    ();
    template<typename Range> ();
    template<typename Func> (, , , );

    // public member functions
     () ;

    // friend functions
    template<typename CharT, typename Traits> 
       
      (, param_type &);
    template<typename CharT, typename Traits> 
       
      (, param_type &);
     (param_type &, param_type &);
     (param_type &, param_type &);
  };

  // construct/copy/destruct
  ();
  template<typename Iter> (, );
  ();
  template<typename Range> ();
  template<typename Func> 
    (, , , );
  (param_type &);

  // public member functions
  template<typename URNG>  () ;
  template<typename URNG>  (, param_type &) ;
   () ;
   () ;
   () ;
  param_type () ;
   (param_type &);
   ();

  // friend functions
  template<typename CharT, typename Traits> 
     
    (, 
               discrete_distribution &);
  template<typename CharT, typename Traits> 
     
    (, 
               discrete_distribution &);
   (discrete_distribution &, 
                  discrete_distribution &);
   (discrete_distribution &, 
                  discrete_distribution &);
};

Description

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

  1. ();

    Creates a new discrete_distribution object that has and .

  2. template<typename Iter> ( first,  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.

  3. ( wl);

    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

    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.

  4. template<typename 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.

  5. template<typename Func> 
      ( nw,  xmin,  xmax,  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 .

  6. (param_type & param);

    Constructs a discrete_distribution from its parameters.

discrete_distribution public member functions

  1. template<typename URNG>  ( urng) ;

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

  2. template<typename URNG> 
       ( urng, param_type & param) ;

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

  3.  () ;

    Returns the smallest value that the distribution can produce.

  4.  () ;

    Returns the largest value that the distribution can produce.

  5.  () ;

    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.

  6. param_type () ;

    Returns the parameters of the distribution.

  7.  (param_type & param);

    Sets the parameters of the distribution.

  8.  ();

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

discrete_distribution friend functions

  1. template<typename CharT, typename Traits> 
       
      ( os, 
                 discrete_distribution & dd);

    Writes a distribution to a std::ostream.

  2. template<typename CharT, typename Traits> 
       
      ( is, 
                 discrete_distribution & dd);

    Reads a distribution from a std::istream

  3.  (discrete_distribution & lhs, 
                    discrete_distribution & rhs);

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

  4.  (discrete_distribution & lhs, 
                    discrete_distribution & rhs);

    Returns true if the two distributions may return different sequences of values, when passed equal generators.


PrevUpHomeNext