Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template discrete_distribution

boost::compute::discrete_distribution — Produces random integers on the interval [0, n), where probability of each integer is given by the weight of the ith integer divided by the sum of all weights.

Synopsis

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

template<typename IntType = uint_> 
class discrete_distribution {
public:
  // types
  typedef IntType result_type;

  // construct/copy/destruct
  discrete_distribution();
  template<typename InputIterator> 
    discrete_distribution(InputIterator, InputIterator);
  ~discrete_distribution();

  // public member functions
  ::std::vector< double > probabilities() const;
  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const;
  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const;
  template<typename OutputIterator, typename Generator> 
    void generate(OutputIterator, OutputIterator, Generator &, 
                  command_queue &);

  // private member functions
   BOOST_STATIC_ASSERT_MSG(boost::is_integral< IntType >::value, 
                           "Template argument must be integral");
};

Description

The following example shows how to setup a discrete distribution to produce 0 and 1 with equal probability


discrete_distribution public construct/copy/destruct

  1. discrete_distribution();

    Creates a new discrete distribution with a single weight p = { 1 }. This distribution produces only zeroes.

  2. template<typename InputIterator> 
      discrete_distribution(InputIterator first, InputIterator last);

    Creates a new discrete distribution with weights given by the range [first, last).

  3. ~discrete_distribution();
    Destroys the discrete_distribution object.

discrete_distribution public member functions

  1. ::std::vector< double > probabilities() const;
    Returns the probabilities.
  2. result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const;
    Returns the minimum potentially generated value.
  3. result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const;
    Returns the maximum potentially generated value.
  4. template<typename OutputIterator, typename Generator> 
      void generate(OutputIterator first, OutputIterator last, 
                    Generator & generator, command_queue & queue);

    Generates uniformly distributed integers and stores them to the range [first, last).

discrete_distribution private member functions

  1.  BOOST_STATIC_ASSERT_MSG(boost::is_integral< IntType >::value, 
                             "Template argument must be integral");

PrevUpHomeNext