...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::compute::uniform_int_distribution — Produces uniformily distributed random integers.
// In header: <boost/compute/random/uniform_int_distribution.hpp> template<typename IntType = uint_> class uniform_int_distribution { public: // types typedef IntType result_type; // construct/copy/destruct explicit uniform_int_distribution(IntType = 0, IntType = (std::numeric_limits< IntType >::max)()); ~uniform_int_distribution(); // public member functions result_type a() const; result_type b() 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"); };
The following example shows how to setup a uniform int distribution to produce random integers 0 and 1.
uniform_int_distribution
public
construct/copy/destructexplicit uniform_int_distribution(IntType a = 0, IntType b = (std::numeric_limits< IntType >::max)());
Creates a new uniform distribution producing numbers in the range [a
, b
].
~uniform_int_distribution();Destroys the
uniform_int_distribution
object. uniform_int_distribution
public member functionsresult_type a() const;Returns the minimum value of the distribution.
result_type b() const;Returns the maximum value of the distribution.
template<typename OutputIterator, typename Generator> void generate(OutputIterator first, OutputIterator last, Generator & generator, command_queue & queue);
Generates uniformily distributed integers and stores them to the range [first
, last
).