...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::random::bernoulli_distribution
// In header: <boost/random/bernoulli_distribution.hpp> template<typename RealType = double> class bernoulli_distribution { public: // types typedef int input_type; typedef bool result_type; // member classes/structs/unions class param_type { public: // types typedef bernoulli_distribution distribution_type; // construct/copy/destruct explicit param_type(RealType = 0.5); // public member functions RealType p() const; // friend functions template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const param_type &); template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, const param_type &); bool operator==(const param_type &, const param_type &); bool operator!=(const param_type &, const param_type &); }; // construct/copy/destruct explicit bernoulli_distribution(const RealType & = 0.5); explicit bernoulli_distribution(const param_type &); // public member functions RealType p() const; bool min() const; bool max() const; param_type param() const; void param(const param_type &); void reset(); template<typename Engine> bool operator()(Engine &) const; template<typename Engine> bool operator()(Engine &, const param_type &) const; // friend functions template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const bernoulli_distribution &); template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, const bernoulli_distribution &); bool operator==(const bernoulli_distribution &, const bernoulli_distribution &); bool operator!=(const bernoulli_distribution &, const bernoulli_distribution &); };
Instantiations of class template bernoulli_distribution model a random distribution . Such a random distribution produces bool values distributed with probabilities P(true) = p and P(false) = 1-p. p is the parameter of the distribution.
bernoulli_distribution
public
construct/copy/destructexplicit bernoulli_distribution(const RealType & p = 0.5);
Constructs a bernoulli_distribution
object. p is the parameter of the distribution.
Requires: 0 <= p <= 1
explicit bernoulli_distribution(const param_type & param);
Constructs bernoulli_distribution
from its parameters
bernoulli_distribution
public member functionsRealType p() const;
Returns: The "p" parameter of the distribution.
bool min() const;
Returns the smallest value that the distribution can produce.
bool max() const;
Returns the largest value that the distribution can produce.
param_type param() const;
Returns the parameters of the distribution.
void param(const param_type & param);
Sets the parameters of the distribution.
void reset();
Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset.
template<typename Engine> bool operator()(Engine & eng) const;
Returns: a random variate distributed according to the bernoulli_distribution
.
template<typename Engine> bool operator()(Engine & eng, const param_type & param) const;
Returns: a random variate distributed according to the bernoulli_distribution
with parameters specified by param.
bernoulli_distribution
friend functionstemplate<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & os, const bernoulli_distribution & bd);
Writes the parameters of the distribution to a std::ostream
.
template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, const bernoulli_distribution & bd);
Reads the parameters of the distribution from a std::istream
.
bool operator==(const bernoulli_distribution & lhs, const bernoulli_distribution & rhs);
Returns true iff the two distributions will produce identical sequences of values given equal generators.
bool operator!=(const bernoulli_distribution & lhs, const bernoulli_distribution & rhs);
Returns true iff the two distributions will produce different sequences of values given equal generators.