Boost C++ 库

...世界上最受尊敬、设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

类模板 bernoulli_distribution - Boost C++ 函数库
PrevUpHomeNext

类模板 bernoulli_distribution

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;

  // member classes/structs/unions

  class param_type {
  public:
    // types
    typedef bernoulli_distribution distribution_type;

    // public member functions
    explicit param_type(RealType = 0.5);
    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 &);
  };

  // public member functions
  explicit bernoulli_distribution(const RealType & = 0.5);
  explicit bernoulli_distribution(const param_type &);
  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 &);
};

描述

类模板 bernoulli_distribution 的实例化模拟了一个 随机分布。这样的随机分布会生成 bool 值,其分布的概率为 P(true) = p 且 P(false) = 1-p。p 是该分布的参数。

bernoulli_distribution 公有成员函数

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

    构造一个 bernoulli_distribution 对象。p 是该分布的参数。

    要求:0 <= p <= 1

  2. explicit bernoulli_distribution(const param_type & param);

    从参数构造 bernoulli_distribution

  3. RealType p() const;

    返回:分布的“p”参数。

  4. bool min() const;

    返回分布可以产生的最小值。

  5. bool max() const;

    返回分布可以产生的最大值。

  6. param_type param() const;

    返回分布的参数。

  7. void param(const param_type & param);

    设置分布的参数。

  8. void reset();

    效果:随后的分布使用不依赖于调用 reset 之前的任何引擎生成的值。

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

    返回:一个根据 bernoulli_distribution 分布的随机变数。

  10. template<typename Engine> 
      bool operator()(Engine & eng, const param_type & param) const;

    返回:一个根据 bernoulli_distribution 分布的随机变数,其参数由 param 指定。

bernoulli_distribution 友元函数

  1. template<typename CharT, typename Traits> 
      std::basic_ostream< CharT, Traits > & 
      operator<<(std::basic_ostream< CharT, Traits > & os, 
                 const bernoulli_distribution & bd);

    将分布的参数写入 std::ostream

  2. template<typename CharT, typename Traits> 
      std::basic_istream< CharT, Traits > & 
      operator>>(std::basic_istream< CharT, Traits > & is, 
                 const bernoulli_distribution & bd);

    std::istream 读取分布的参数。

  3. bool operator==(const bernoulli_distribution & lhs, 
                    const bernoulli_distribution & rhs);

    当给定相同的生成器时,当且仅当两个分布将产生相同的数值序列时返回 true。

  4. bool operator!=(const bernoulli_distribution & lhs, 
                    const bernoulli_distribution & rhs);

    当给定相同的生成器时,当且仅当两个分布将产生不同的数值序列时返回 true。


PrevUpHomeNext