...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::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; // construct/copy/destruct bernoulli_distribution(const RealType & = RealType(0.5)); // public member functions RealType p() const; void reset() ; template<typename Engine> result_type operator()(Engine &) ; // friend functions template<typename CharT, typename Traits> friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const bernoulli_distribution &) ; template<typename CharT, typename Traits> friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, 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/destructbernoulli_distribution(const RealType & p_arg = RealType(0.5));
Constructs a bernoulli_distribution
object. p is the parameter of the distribution.
Requires: 0 <= p <= 1
bernoulli_distribution
public member functionsRealType p() const;
Returns: The "p" parameter 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> result_type operator()(Engine & eng) ;
Returns: a random variate distributed according to the bernoulli_distribution
.
bernoulli_distribution
friend functionstemplate<typename CharT, typename Traits> friend 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> friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, bernoulli_distribution & bd) ;
Reads the parameters of the distribution from a std::istream
.