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 for the latest Boost documentation.
PrevUpHomeNext

Class template bernoulli_distribution

boost::random::bernoulli_distribution

Synopsis

// 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> 
      friend std::basic_ostream< CharT, Traits > & 
      operator<<(std::basic_ostream< CharT, Traits > &, const param_type &);
    template<typename CharT, typename Traits> 
      friend std::basic_istream< CharT, Traits > & 
      operator>>(std::basic_istream< CharT, Traits > &, const param_type &);
    friend bool operator==(const param_type &, const param_type &);
    friend 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> 
    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 > &, 
               const bernoulli_distribution &);
  friend bool operator==(const bernoulli_distribution &, 
                         const bernoulli_distribution &);
  friend bool operator!=(const bernoulli_distribution &, 
                         const bernoulli_distribution &);
};

Description

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/destruct

  1. explicit bernoulli_distribution(const RealType & p = 0.5);

    Constructs a bernoulli_distribution object. p is the parameter of the distribution.

    Requires: 0 <= p <= 1

  2. explicit bernoulli_distribution(const param_type & param);

    Constructs bernoulli_distribution from its parameters

bernoulli_distribution public member functions

  1. RealType p() const;

    Returns: The "p" parameter of the distribution.

  2. bool min() const;

    Returns the smallest value that the distribution can produce.

  3. bool max() const;

    Returns the largest value that the distribution can produce.

  4. param_type param() const;

    Returns the parameters of the distribution.

  5. void param(const param_type & param);

    Sets the parameters of the distribution.

  6. void reset();

    Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset.

  7. template<typename Engine> bool operator()(Engine & eng) const;

    Returns: a random variate distributed according to the bernoulli_distribution .

  8. 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 functions

  1. template<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.

  2. template<typename CharT, typename Traits> 
      friend 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.

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

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


PrevUpHomeNext