// random number generation -*- C++ -*-
-// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2009-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
__mod(_Tp __x)
{ return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
+ /* Determine whether number is a power of 2. */
+ template<typename _Tp>
+ inline bool
+ _Power_of_2(_Tp __x)
+ {
+ return ((__x - 1) & __x) == 0;
+ };
+
/*
* An adaptor class for converting the output of any Generator into
* the input for a specific Distribution.
#ifdef _GLIBCXX_USE_RANDOM_TR1
explicit
- random_device(const std::string& __token = "/dev/urandom")
+ random_device(const std::string& __token = "default")
{
- if ((__token != "/dev/urandom" && __token != "/dev/random")
- || !(_M_file = std::fopen(__token.c_str(), "rb")))
- std::__throw_runtime_error(__N("random_device::"
- "random_device(const std::string&)"));
+ _M_init(__token);
}
~random_device()
- { std::fclose(_M_file); }
+ { _M_fini(); }
#else
explicit
random_device(const std::string& __token = "mt19937")
- : _M_mt(_M_strtoul(__token)) { }
-
- private:
- static unsigned long
- _M_strtoul(const std::string& __str)
- {
- unsigned long __ret = 5489UL;
- if (__str != "mt19937")
- {
- const char* __nptr = __str.c_str();
- char* __endptr;
- __ret = std::strtoul(__nptr, &__endptr, 0);
- if (*__nptr == '\0' || *__endptr != '\0')
- std::__throw_runtime_error(__N("random_device::_M_strtoul"
- "(const std::string&)"));
- }
- return __ret;
- }
+ { _M_init_pretr1(__token); }
public:
operator()()
{
#ifdef _GLIBCXX_USE_RANDOM_TR1
- result_type __ret;
- std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
- 1, _M_file);
- return __ret;
+ return this->_M_getval();
#else
- return _M_mt();
+ return this->_M_getval_pretr1();
#endif
}
private:
-#ifdef _GLIBCXX_USE_RANDOM_TR1
- FILE* _M_file;
-#else
- mt19937 _M_mt;
-#endif
+ void _M_init(const std::string& __token);
+ void _M_init_pretr1(const std::string& __token);
+ void _M_fini();
+
+ result_type _M_getval();
+ result_type _M_getval_pretr1();
+
+ union
+ {
+ void* _M_file;
+ mt19937 _M_mt;
+ };
};
/* @} */ // group random_generators
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two uniform integer distributions have
+ * the same parameters.
+ */
+ friend bool
+ operator==(const uniform_int_distribution& __d1,
+ const uniform_int_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
+ private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two uniform integer distributions have
- * the same parameters.
- */
- template<typename _IntType>
- inline bool
- operator==(const std::uniform_int_distribution<_IntType>& __d1,
- const std::uniform_int_distribution<_IntType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two uniform integer distributions have
* different parameters.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
return (__aurng() * (__p.b() - __p.a())) + __p.a();
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two uniform real distributions have
+ * the same parameters.
+ */
+ friend bool
+ operator==(const uniform_real_distribution& __d1,
+ const uniform_real_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two uniform real distributions have
- * the same parameters.
- */
- template<typename _IntType>
- inline bool
- operator==(const std::uniform_real_distribution<_IntType>& __d1,
- const std::uniform_real_distribution<_IntType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two uniform real distributions have
* different parameters.
*/
result_type
min() const
- { return std::numeric_limits<result_type>::min(); }
+ { return std::numeric_limits<result_type>::lowest(); }
/**
* @brief Returns the least upper bound value of the distribution.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two normal distributions have
* the same parameters and the sequences that would
std::normal_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
result_type _M_saved;
bool _M_saved_available;
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
const param_type& __p)
{ return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two lognormal distributions have
* the same parameters and the sequences that would
friend bool
operator==(const lognormal_distribution& __d1,
const lognormal_distribution& __d2)
- { return (__d1.param() == __d2.param()
+ { return (__d1._M_param == __d2._M_param
&& __d1._M_nd == __d2._M_nd); }
/**
std::lognormal_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two gamma distributions have the same
* parameters and the sequences that would be generated
friend bool
operator==(const gamma_distribution& __d1,
const gamma_distribution& __d2)
- { return (__d1.param() == __d2.param()
+ { return (__d1._M_param == __d2._M_param
&& __d1._M_nd == __d2._M_nd); }
/**
std::gamma_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
return 2 * _M_gd(__urng, param_type(__p.n() / 2));
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.n() / 2);
+ this->__generate_impl(__f, __t, __urng, __p2); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.n() / 2);
+ this->__generate_impl(__f, __t, __urng, __p2); }
+
/**
* @brief Return true if two Chi-squared distributions have
* the same parameters and the sequences that would be
friend bool
operator==(const chi_squared_distribution& __d1,
const chi_squared_distribution& __d2)
- { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+ { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
/**
* @brief Inserts a %chi_squared_distribution random number distribution
std::chi_squared_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const typename
+ std::gamma_distribution<result_type>::param_type& __p);
+
param_type _M_param;
std::gamma_distribution<result_type> _M_gd;
*/
result_type
min() const
- { return std::numeric_limits<result_type>::min(); }
+ { return std::numeric_limits<result_type>::lowest(); }
/**
* @brief Returns the least upper bound value of the distribution.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two Cauchy distributions have
+ * the same parameters.
+ */
+ friend bool
+ operator==(const cauchy_distribution& __d1,
+ const cauchy_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two Cauchy distributions have
- * the same parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::cauchy_distribution<_RealType>& __d1,
- const std::cauchy_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two Cauchy distributions have
* different parameters.
/ (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Fisher f distributions have
* the same parameters and the sequences that would
friend bool
operator==(const fisher_f_distribution& __d1,
const fisher_f_distribution& __d2)
- { return (__d1.param() == __d2.param()
+ { return (__d1._M_param == __d2._M_param
&& __d1._M_gd_x == __d2._M_gd_x
&& __d1._M_gd_y == __d2._M_gd_y); }
std::fisher_f_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
};
/**
- * @brief Return true if two Fisher f distributions are diferent.
+ * @brief Return true if two Fisher f distributions are different.
*/
template<typename _RealType>
inline bool
*/
result_type
min() const
- { return std::numeric_limits<result_type>::min(); }
+ { return std::numeric_limits<result_type>::lowest(); }
/**
* @brief Returns the least upper bound value of the distribution.
return _M_nd(__urng) * std::sqrt(__p.n() / __g);
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Student t distributions have
* the same parameters and the sequences that would
friend bool
operator==(const student_t_distribution& __d1,
const student_t_distribution& __d2)
- { return (__d1.param() == __d2.param()
+ { return (__d1._M_param == __d2._M_param
&& __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
/**
std::student_t_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
return false;
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng, const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two Bernoulli distributions have
+ * the same parameters.
+ */
+ friend bool
+ operator==(const bernoulli_distribution& __d1,
+ const bernoulli_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two Bernoulli distributions have
- * the same parameters.
- */
- inline bool
- operator==(const std::bernoulli_distribution& __d1,
- const std::bernoulli_distribution& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two Bernoulli distributions have
* different parameters.
* @brief A discrete binomial random number distribution.
*
* The formula for the binomial probability density function is
- * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
+ * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
* and @f$p@f$ are the parameters of the distribution.
*/
template<typename _IntType = int>
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two binomial distributions have
* the same parameters and the sequences that would
operator==(const binomial_distribution& __d1,
const binomial_distribution& __d2)
#ifdef _GLIBCXX_USE_C99_MATH_TR1
- { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
+ { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
#else
- { return __d1.param() == __d2.param(); }
+ { return __d1._M_param == __d2._M_param; }
#endif
/**
std::binomial_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
template<typename _UniformRandomNumberGenerator>
result_type
- _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
+ _M_waiting(_UniformRandomNumberGenerator& __urng,
+ _IntType __t, double __q);
param_type _M_param;
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two geometric distributions have
+ * the same parameters.
+ */
+ friend bool
+ operator==(const geometric_distribution& __d1,
+ const geometric_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two geometric distributions have
- * the same parameters.
- */
- template<typename _IntType>
- inline bool
- operator==(const std::geometric_distribution<_IntType>& __d1,
- const std::geometric_distribution<_IntType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two geometric distributions have
* different parameters.
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two negative binomial distributions have
* the same parameters and the sequences that would be
friend bool
operator==(const negative_binomial_distribution& __d1,
const negative_binomial_distribution& __d2)
- { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+ { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
/**
* @brief Inserts a %negative_binomial_distribution random
std::negative_binomial_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::gamma_distribution<double> _M_gd;
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Poisson distributions have the same
* parameters and the sequences that would be generated
operator==(const poisson_distribution& __d1,
const poisson_distribution& __d2)
#ifdef _GLIBCXX_USE_C99_MATH_TR1
- { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
+ { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
#else
- { return __d1.param() == __d2.param(); }
+ { return __d1._M_param == __d2._M_param; }
#endif
/**
std::poisson_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
// NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
{
__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
__aurng(__urng);
- return -std::log(__aurng()) / __p.lambda();
+ return -std::log(result_type(1) - __aurng()) / __p.lambda();
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two exponential distributions have the same
+ * parameters.
+ */
+ friend bool
+ operator==(const exponential_distribution& __d1,
+ const exponential_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two exponential distributions have the same
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::exponential_distribution<_RealType>& __d1,
- const std::exponential_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two exponential distributions have different
* parameters.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two Weibull distributions have the same
+ * parameters.
+ */
+ friend bool
+ operator==(const weibull_distribution& __d1,
+ const weibull_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two Weibull distributions have the same
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::weibull_distribution<_RealType>& __d1,
- const std::weibull_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two Weibull distributions have different
* parameters.
*/
result_type
min() const
- { return std::numeric_limits<result_type>::min(); }
+ { return std::numeric_limits<result_type>::lowest(); }
/**
* @brief Returns the least upper bound value of the distribution.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two extreme value distributions have the same
+ * parameters.
+ */
+ friend bool
+ operator==(const extreme_value_distribution& __d1,
+ const extreme_value_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two extreme value distributions have the same
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::extreme_value_distribution<_RealType>& __d1,
- const std::extreme_value_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two extreme value distributions have different
* parameters.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two discrete distributions have the same
+ * parameters.
+ */
+ friend bool
+ operator==(const discrete_distribution& __d1,
+ const discrete_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
/**
* @brief Inserts a %discrete_distribution random number distribution
* @p __x into the output stream @p __os.
std::discrete_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two discrete distributions have the same
- * parameters.
- */
- template<typename _IntType>
- inline bool
- operator==(const std::discrete_distribution<_IntType>& __d1,
- const std::discrete_distribution<_IntType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two discrete distributions have different
* parameters.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two piecewise constant distributions have the
+ * same parameters.
+ */
+ friend bool
+ operator==(const piecewise_constant_distribution& __d1,
+ const piecewise_constant_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
/**
- * @brief Inserts a %piecewise_constan_distribution random
+ * @brief Inserts a %piecewise_constant_distribution random
* number distribution @p __x into the output stream @p __os.
*
* @param __os An output stream.
- * @param __x A %piecewise_constan_distribution random number
+ * @param __x A %piecewise_constant_distribution random number
* distribution.
*
* @returns The output stream with the state of @p __x inserted or in
const std::piecewise_constant_distribution<_RealType1>& __x);
/**
- * @brief Extracts a %piecewise_constan_distribution random
+ * @brief Extracts a %piecewise_constant_distribution random
* number distribution @p __x from the input stream @p __is.
*
* @param __is An input stream.
- * @param __x A %piecewise_constan_distribution random number
+ * @param __x A %piecewise_constant_distribution random number
* generator engine.
*
* @returns The input stream with @p __x extracted or in an error
std::piecewise_constant_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two piecewise constant distributions have the
- * same parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
- const std::piecewise_constant_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two piecewise constant distributions have
* different parameters.
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, this->param()); }
+ { return this->operator()(__urng, _M_param); }
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, _M_param); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ /**
+ * @brief Return true if two piecewise linear distributions have the
+ * same parameters.
+ */
+ friend bool
+ operator==(const piecewise_linear_distribution& __d1,
+ const piecewise_linear_distribution& __d2)
+ { return __d1._M_param == __d2._M_param; }
+
/**
* @brief Inserts a %piecewise_linear_distribution random number
* distribution @p __x into the output stream @p __os.
std::piecewise_linear_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
- /**
- * @brief Return true if two piecewise linear distributions have the
- * same parameters.
- */
- template<typename _RealType>
- inline bool
- operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
- const std::piecewise_linear_distribution<_RealType>& __d2)
- { return __d1.param() == __d2.param(); }
-
/**
* @brief Return true if two piecewise linear distributions have
* different parameters.