| Home | Libraries | People | FAQ | More

## Class template binomial_distribution

boost::binomial_distribution

## Synopsis

    // In header: <boost/random/binomial_distribution.hpp>

    template<typename IntType = int, typename RealType = double>
    class binomial_distribution {
    public:
      // types
      typedef bernoulli_distribution< RealType >::input_type input_type;
      typedef IntType                                        result_type;

      // construct/copy/destruct
      binomial_distribution(IntType = 1, const RealType & = RealType(0.5));

      // public member functions
      IntType t() const;
      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 binomial_distribution &) ;
      template<typename CharT, typename Traits>
        friend std::basic_istream< CharT, Traits > &
        operator>>(std::basic_istream< CharT, Traits > &, binomial_distribution &) ;
    };

## Description

The binomial distribution is an integer valued distribution with two parameters, `t` and `p`. The values of the distribution are within the range [0,t].

The probability that the distribution produces a value k is .

### `binomial_distribution` public construct/copy/destruct

1.     binomial_distribution(IntType t = 1, const RealType & p = RealType(0.5));

   Construct an `binomial_distribution` object. `t` and `p` are the parameters of the distribution.

   Requires: t >=0 && 0 <= p <= 1

### `binomial_distribution` public member functions

1.     IntType t() const;

   Returns: the `t` parameter of the distribution

2.     RealType p() const;

   Returns: the `p` parameter of the distribution

3.     void reset() ;

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

4.     template<typename Engine> result_type operator()(Engine & eng) ;

   Returns: a random variate distributed according to the binomial distribution.

### `binomial_distribution` friend functions

1.     template<typename CharT, typename Traits>
         friend std::basic_ostream< CharT, Traits > &
         operator<<(std::basic_ostream< CharT, Traits > & os,
                    const binomial_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,
                    binomial_distribution & bd) ;

   Reads the parameters of the distribution from a `std::istream`.