+ /** Returns true if the parameters have the same values. */
+ friend bool operator==(const param_type& lhs, const param_type& rhs)
+ {
+ return lhs._t == rhs._t && lhs._p == rhs._p;
+ }
+ /** Returns true if the parameters have different values. */
+ friend bool operator!=(const param_type& lhs, const param_type& rhs)
+ {
+ return !(lhs == rhs);
+ }
+ private:
+ IntType _t;
+ RealType _p;
+ };
+
+ /**
+ * Construct a @c binomial_distribution object. @c t and @c p
+ * are the parameters of the distribution.
+ *
+ * Requires: t >=0 && 0 <= p <= 1
+ */
+ explicit binomial_distribution(IntType t_arg = 1,
+ RealType p_arg = RealType(0.5))
+ : _t(t_arg), _p(p_arg)
+ {
+ init();
+ }
+
+ /**
+ * Construct an @c binomial_distribution object from the
+ * parameters.
+ */
+ explicit binomial_distribution(const param_type& parm)
+ : _t(parm.t()), _p(parm.p())
+ {
+ init();
+ }
+
+ /**
+ * Returns a random variate distributed according to the
+ * binomial distribution.
+ */
+ template<class URNG>
+ IntType operator()(URNG& urng) const
+ {
+ if(use_inversion()) {
+ if(0.5 < _p) {
+ return _t - invert(_t, 1-_p, urng);
+ } else {
+ return invert(_t, _p, urng);
+ }
+ } else if(0.5 < _p) {
+ return _t - generate(urng);
+ } else {
+ return generate(urng);
+ }
+ }
+
+ /**
+ * Returns a random variate distributed according to the
+ * binomial distribution with parameters specified by @c param.
+ */
+ template<class URNG>
+ IntType operator()(URNG& urng, const param_type& parm) const
+ {
+ return binomial_distribution(parm)(urng);
+ }
+
+ /** Returns the @c t parameter of the distribution. */
+ IntType t() const { return _t; }
+ /** Returns the @c p parameter of the distribution. */
+ RealType p() const { return _p; }
+
+ /** Returns the smallest value that the distribution can produce. */
+ IntType min BOOST_PREVENT_MACRO_SUBSTITUTION() const { return 0; }
+ /** Returns the largest value that the distribution can produce. */
+ IntType max BOOST_PREVENT_MACRO_SUBSTITUTION() const { return _t; }
+
+ /** Returns the parameters of the distribution. */
+ param_type param() const { return param_type(_t, _p); }
+ /** Sets parameters of the distribution. */
+ void param(const param_type& parm)
+ {
+ _t = parm.t();
+ _p = parm.p();
+ init();
+ }
+
+ /**
+ * Effects: Subsequent uses of the distribution do not depend
+ * on values produced by any engine prior to invoking reset.
+ */
+ void reset() { }
+
+#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
+ /** Writes the parameters of the distribution to a @c std::ostream. */
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os,
+ const binomial_distribution& bd)
+ {
+ os << bd.param();
+ return os;
+ }
+
+ /** Reads the parameters of the distribution from a @c std::istream. */
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, binomial_distribution& bd)
+ {
+ bd.read(is);
+ return is;
+ }
+#endif
+
+ /** Returns true if the two distributions will produce the same
+ sequence of values, given equal generators. */
+ friend bool operator==(const binomial_distribution& lhs,
+ const binomial_distribution& rhs)
+ {
+ return lhs._t == rhs._t && lhs._p == rhs._p;
+ }
+ /** Returns true if the two distributions could produce different
+ sequences of values, given equal generators. */
+ friend bool operator!=(const binomial_distribution& lhs,
+ const binomial_distribution& rhs)
+ {
+ return !(lhs == rhs);
+ }