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 = 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 &);
};

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> (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.

  3. (WeightType > 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> (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.

  5. 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 .

  6. (const param_type & param);

    Constructs a discrete_distribution from its parameters.

discrete_distribution public member functions

  1. template<typename URNG> IntType (URNG & urng) ;

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

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

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

  3. result_type () ;

    Returns the smallest value that the distribution can produce.

  4. result_type () ;

    Returns the largest value that the distribution can produce.

  5. 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.

  6. param_type () ;

    Returns the parameters of the distribution.

  7. void (const param_type & param);

    Sets the parameters of the distribution.

  8. void ();

    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> 
      CharT, Traits > & 
      (CharT, Traits > & os, 
                 const discrete_distribution & dd);

    Writes a distribution to a std::ostream.

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

    Reads a distribution from a std::istream

  3. 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.

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


PrevUpHomeNext