31 #ifndef _GLIBCXX_TR1_RANDOM_H
32 #define _GLIBCXX_TR1_RANDOM_H 1
34 #pragma GCC system_header
53 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 template<
typename _UIntType,
int __w,
56 bool = __w < std::numeric_limits<_UIntType>::digits>
58 {
static const _UIntType __value = 0; };
60 template<
typename _UIntType,
int __w>
61 struct _Shift<_UIntType, __w,
true>
62 {
static const _UIntType __value = _UIntType(1) << __w; };
64 template<
typename _Tp, _Tp __a, _Tp __c, _Tp __m,
bool>
69 template<
typename _Tp, _Tp __a, _Tp __c, _Tp __m>
72 {
return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
74 typedef __gnu_cxx::__conditional_type<(
sizeof(unsigned) == 4),
75 unsigned,
unsigned long>::__type _UInt32Type;
81 template<
typename _Engine,
typename _Distribution>
84 typedef typename remove_reference<_Engine>::type _BEngine;
85 typedef typename _BEngine::result_type _Engine_result_type;
86 typedef typename _Distribution::input_type result_type;
89 _Adaptor(
const _Engine& __g)
95 result_type __return_value;
96 if (is_integral<_Engine_result_type>::value
97 && is_integral<result_type>::value)
98 __return_value = _M_g.min();
100 __return_value = result_type(0);
101 return __return_value;
107 result_type __return_value;
108 if (is_integral<_Engine_result_type>::value
109 && is_integral<result_type>::value)
110 __return_value = _M_g.max();
111 else if (!is_integral<result_type>::value)
112 __return_value = result_type(1);
115 return __return_value;
130 result_type __return_value;
131 if (is_integral<_Engine_result_type>::value
132 && is_integral<result_type>::value)
133 __return_value = _M_g();
134 else if (!is_integral<_Engine_result_type>::value
135 && !is_integral<result_type>::value)
136 __return_value = result_type(_M_g() - _M_g.min())
137 / result_type(_M_g.max() - _M_g.min());
138 else if (is_integral<_Engine_result_type>::value
139 && !is_integral<result_type>::value)
140 __return_value = result_type(_M_g() - _M_g.min())
141 / result_type(_M_g.max() - _M_g.min() + result_type(1));
143 __return_value = (((_M_g() - _M_g.min())
144 / (_M_g.max() - _M_g.min()))
146 return __return_value;
154 template<
typename _Engine,
typename _Distribution>
155 struct _Adaptor<_Engine*, _Distribution>
157 typedef typename _Engine::result_type _Engine_result_type;
158 typedef typename _Distribution::input_type result_type;
161 _Adaptor(_Engine* __g)
167 result_type __return_value;
168 if (is_integral<_Engine_result_type>::value
169 && is_integral<result_type>::value)
170 __return_value = _M_g->min();
172 __return_value = result_type(0);
173 return __return_value;
179 result_type __return_value;
180 if (is_integral<_Engine_result_type>::value
181 && is_integral<result_type>::value)
182 __return_value = _M_g->max();
183 else if (!is_integral<result_type>::value)
184 __return_value = result_type(1);
187 return __return_value;
193 result_type __return_value;
194 if (is_integral<_Engine_result_type>::value
195 && is_integral<result_type>::value)
196 __return_value = (*_M_g)();
197 else if (!is_integral<_Engine_result_type>::value
198 && !is_integral<result_type>::value)
199 __return_value = result_type((*_M_g)() - _M_g->min())
200 / result_type(_M_g->max() - _M_g->min());
201 else if (is_integral<_Engine_result_type>::value
202 && !is_integral<result_type>::value)
203 __return_value = result_type((*_M_g)() - _M_g->min())
204 / result_type(_M_g->max() - _M_g->min() + result_type(1));
206 __return_value = ((((*_M_g)() - _M_g->min())
207 / (_M_g->max() - _M_g->min()))
209 return __return_value;
216 _GLIBCXX_END_NAMESPACE_VERSION
219 _GLIBCXX_BEGIN_NAMESPACE_VERSION
227 template<
typename _Engine,
typename _Dist>
228 class variate_generator
236 typedef _Engine engine_type;
237 typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type;
238 typedef _Dist distribution_type;
239 typedef typename _Dist::result_type result_type;
242 typedef typename __gnu_cxx::__enable_if<
243 is_arithmetic<result_type>::value, result_type>::__type _IsValidType;
252 variate_generator(engine_type __eng, distribution_type __dist)
253 : _M_engine(__eng), _M_dist(__dist) { }
260 {
return _M_dist(_M_engine); }
265 template<
typename _Tp>
267 operator()(_Tp __value)
268 {
return _M_dist(_M_engine, __value); }
276 {
return _M_engine; }
282 const engine_value_type&
284 {
return _M_engine; }
296 const distribution_type&
305 {
return this->distribution().min(); }
312 {
return this->distribution().max(); }
315 engine_value_type _M_engine;
316 distribution_type _M_dist;
355 template<
class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
356 class linear_congruential
363 typedef _UIntType result_type;
366 static const _UIntType multiplier = __a;
368 static const _UIntType increment = __c;
370 static const _UIntType modulus = __m;
379 linear_congruential(
unsigned long __x0 = 1)
380 { this->seed(__x0); }
389 linear_congruential(_Gen& __g)
399 seed(
unsigned long __s = 1);
410 { seed(__g,
typename is_fundamental<_Gen>::type()); }
420 {
return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
446 const linear_congruential& __rhs)
447 {
return __lhs._M_x == __rhs._M_x; }
460 const linear_congruential& __rhs)
461 {
return !(__lhs == __rhs); }
470 template<
class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
472 typename _CharT,
typename _Traits>
473 friend std::basic_ostream<_CharT, _Traits>&
474 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
475 const linear_congruential<_UIntType1, __a1, __c1,
491 template<
class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
493 typename _CharT,
typename _Traits>
494 friend std::basic_istream<_CharT, _Traits>&
495 operator>>(std::basic_istream<_CharT, _Traits>& __is,
496 linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr);
502 {
return seed(static_cast<unsigned long>(__g)); }
514 typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0;
519 typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand;
547 template<
class _UIntType,
int __w,
int __n,
int __m,
int __r,
548 _UIntType __a,
int __u,
int __s, _UIntType __b,
int __t,
549 _UIntType __c,
int __l>
550 class mersenne_twister
556 typedef _UIntType result_type;
559 static const
int word_size = __w;
560 static const
int state_size = __n;
561 static const
int shift_size = __m;
562 static const
int mask_bits = __r;
563 static const _UIntType parameter_a = __a;
564 static const
int output_u = __u;
565 static const
int output_s = __s;
566 static const _UIntType output_b = __b;
567 static const
int output_t = __t;
568 static const _UIntType output_c = __c;
569 static const
int output_l = __l;
576 mersenne_twister(
unsigned long __value)
580 mersenne_twister(_Gen& __g)
588 seed(
unsigned long __value);
593 { seed(__g,
typename is_fundamental<_Gen>::type()); }
601 {
return __detail::_Shift<_UIntType, __w>::__value - 1; }
618 const mersenne_twister& __rhs)
619 {
return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
633 const mersenne_twister& __rhs)
634 {
return !(__lhs == __rhs); }
646 template<
class _UIntType1,
int __w1,
int __n1,
int __m1,
int __r1,
647 _UIntType1 __a1,
int __u1,
int __s1, _UIntType1 __b1,
int __t1,
648 _UIntType1 __c1,
int __l1,
649 typename _CharT,
typename _Traits>
650 friend std::basic_ostream<_CharT, _Traits>&
651 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
652 const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
653 __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
665 template<
class _UIntType1,
int __w1,
int __n1,
int __m1,
int __r1,
666 _UIntType1 __a1,
int __u1,
int __s1, _UIntType1 __b1,
int __t1,
667 _UIntType1 __c1,
int __l1,
668 typename _CharT,
typename _Traits>
669 friend std::basic_istream<_CharT, _Traits>&
670 operator>>(std::basic_istream<_CharT, _Traits>& __is,
671 mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
672 __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
678 {
return seed(static_cast<unsigned long>(__g)); }
684 _UIntType _M_x[state_size];
696 typedef mersenne_twister<
697 unsigned long, 32, 624, 397, 31,
724 template<
typename _IntType, _IntType __m,
int __s,
int __r>
725 class subtract_with_carry
731 typedef _IntType result_type;
734 static const _IntType modulus = __m;
735 static const
int long_lag = __r;
736 static const
int short_lag = __s;
742 subtract_with_carry()
750 subtract_with_carry(
unsigned long __value)
751 { this->seed(__value); }
760 subtract_with_carry(_Gen& __g)
775 seed(
unsigned long __value = 19780503);
784 { seed(__g,
typename is_fundamental<_Gen>::type()); }
800 {
return this->modulus - 1; }
820 const subtract_with_carry& __rhs)
821 {
return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
835 const subtract_with_carry& __rhs)
836 {
return !(__lhs == __rhs); }
848 template<
typename _IntType1, _IntType1 __m1,
int __s1,
int __r1,
849 typename _CharT,
typename _Traits>
850 friend std::basic_ostream<_CharT, _Traits>&
851 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
852 const subtract_with_carry<_IntType1, __m1, __s1,
865 template<
typename _IntType1, _IntType1 __m1,
int __s1,
int __r1,
866 typename _CharT,
typename _Traits>
867 friend std::basic_istream<_CharT, _Traits>&
868 operator>>(std::basic_istream<_CharT, _Traits>& __is,
869 subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x);
875 {
return seed(static_cast<unsigned long>(__g)); }
881 typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType;
883 _UIntType _M_x[long_lag];
897 template<
typename _RealType,
int __w,
int __s,
int __r>
898 class subtract_with_carry_01
902 typedef _RealType result_type;
905 static const int word_size = __w;
906 static const int long_lag = __r;
907 static const int short_lag = __s;
913 subtract_with_carry_01()
916 _M_initialize_npows();
924 subtract_with_carry_01(
unsigned long __value)
927 _M_initialize_npows();
937 subtract_with_carry_01(_Gen& __g)
940 _M_initialize_npows();
947 seed(
unsigned long __value = 19780503);
956 { seed(__g,
typename is_fundamental<_Gen>::type()); }
992 operator==(
const subtract_with_carry_01& __lhs,
993 const subtract_with_carry_01& __rhs)
995 for (
int __i = 0; __i < long_lag; ++__i)
996 if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n,
1015 operator!=(
const subtract_with_carry_01& __lhs,
1016 const subtract_with_carry_01& __rhs)
1017 {
return !(__lhs == __rhs); }
1029 template<
typename _RealType1,
int __w1,
int __s1,
int __r1,
1030 typename _CharT,
typename _Traits>
1031 friend std::basic_ostream<_CharT, _Traits>&
1032 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1033 const subtract_with_carry_01<_RealType1, __w1, __s1,
1046 template<
typename _RealType1,
int __w1,
int __s1,
int __r1,
1047 typename _CharT,
typename _Traits>
1048 friend std::basic_istream<_CharT, _Traits>&
1049 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1050 subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x);
1053 template<
class _Gen>
1056 {
return seed(static_cast<unsigned long>(__g)); }
1058 template<
class _Gen>
1063 _M_initialize_npows();
1065 static const int __n = (__w + 31) / 32;
1067 typedef __detail::_UInt32Type _UInt32Type;
1068 _UInt32Type _M_x[long_lag][__n];
1069 _RealType _M_npows[__n];
1070 _UInt32Type _M_carry;
1074 typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
1078 typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01;
1087 template<
class _UniformRandomNumberGenerator,
int __p,
int __r>
1095 typedef _UniformRandomNumberGenerator base_type;
1097 typedef typename base_type::result_type result_type;
1100 static const int block_size = __p;
1101 static const int used_block = __r;
1118 discard_block(
const base_type& __rng)
1119 : _M_b(__rng), _M_n(0) { }
1128 discard_block(
unsigned long __s)
1129 : _M_b(__s), _M_n(0) { }
1136 template<
class _Gen>
1137 discard_block(_Gen& __g)
1138 : _M_b(__g), _M_n(0) { }
1155 template<
class _Gen>
1156 void seed(_Gen& __g)
1174 {
return _M_b.min(); }
1181 {
return _M_b.max(); }
1200 operator==(
const discard_block& __lhs,
const discard_block& __rhs)
1201 {
return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
1214 operator!=(
const discard_block& __lhs,
const discard_block& __rhs)
1215 {
return !(__lhs == __rhs); }
1227 template<
class _UniformRandomNumberGenerator1,
int __p1,
int __r1,
1228 typename _CharT,
typename _Traits>
1229 friend std::basic_ostream<_CharT, _Traits>&
1230 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1231 const discard_block<_UniformRandomNumberGenerator1,
1244 template<
class _UniformRandomNumberGenerator1,
int __p1,
int __r1,
1245 typename _CharT,
typename _Traits>
1246 friend std::basic_istream<_CharT, _Traits>&
1247 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1248 discard_block<_UniformRandomNumberGenerator1,
1260 typedef discard_block<
1261 subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
1269 typedef discard_block<
1270 subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
1275 typedef discard_block<
1276 subtract_with_carry_01<float, 24, 10, 24>,
1281 typedef discard_block<
1282 subtract_with_carry_01<float, 24, 10, 24>,
1292 template<
class _UniformRandomNumberGenerator1,
int __s1,
1293 class _UniformRandomNumberGenerator2,
int __s2>
1303 typedef _UniformRandomNumberGenerator1 base1_type;
1305 typedef _UniformRandomNumberGenerator2 base2_type;
1308 typedef typename base1_type::result_type _Result_type1;
1309 typedef typename base2_type::result_type _Result_type2;
1313 typedef typename __gnu_cxx::__conditional_type<(
sizeof(_Result_type1)
1314 >
sizeof(_Result_type2)),
1315 _Result_type1, _Result_type2>::__type result_type;
1318 static const int shift1 = __s1;
1319 static const int shift2 = __s2;
1324 { _M_initialize_max(); }
1326 xor_combine(
const base1_type& __rng1,
const base2_type& __rng2)
1327 : _M_b1(__rng1), _M_b2(__rng2)
1328 { _M_initialize_max(); }
1330 xor_combine(
unsigned long __s)
1331 : _M_b1(__s), _M_b2(__s + 1)
1332 { _M_initialize_max(); }
1334 template<
class _Gen>
1335 xor_combine(_Gen& __g)
1336 : _M_b1(__g), _M_b2(__g)
1337 { _M_initialize_max(); }
1346 template<
class _Gen>
1377 return ((result_type(_M_b1() - _M_b1.min()) << shift1)
1378 ^ (result_type(_M_b2() - _M_b2.min()) << shift2));
1392 operator==(
const xor_combine& __lhs,
const xor_combine& __rhs)
1394 return (__lhs.base1() == __rhs.base1())
1395 && (__lhs.base2() == __rhs.base2());
1409 operator!=(
const xor_combine& __lhs,
const xor_combine& __rhs)
1410 {
return !(__lhs == __rhs); }
1422 template<
class _UniformRandomNumberGenerator11,
int __s11,
1423 class _UniformRandomNumberGenerator21,
int __s21,
1424 typename _CharT,
typename _Traits>
1425 friend std::basic_ostream<_CharT, _Traits>&
1426 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1427 const xor_combine<_UniformRandomNumberGenerator11, __s11,
1428 _UniformRandomNumberGenerator21, __s21>& __x);
1440 template<
class _UniformRandomNumberGenerator11,
int __s11,
1441 class _UniformRandomNumberGenerator21,
int __s21,
1442 typename _CharT,
typename _Traits>
1443 friend std::basic_istream<_CharT, _Traits>&
1444 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1445 xor_combine<_UniformRandomNumberGenerator11, __s11,
1446 _UniformRandomNumberGenerator21, __s21>& __x);
1450 _M_initialize_max();
1453 _M_initialize_max_aux(result_type, result_type,
int);
1469 typedef unsigned int result_type;
1473 #ifdef _GLIBCXX_USE_RANDOM_TR1
1476 random_device(
const std::string& __token =
"/dev/urandom")
1478 if ((__token !=
"/dev/urandom" && __token !=
"/dev/random")
1479 || !(_M_file = std::fopen(__token.c_str(),
"rb")))
1480 std::__throw_runtime_error(__N(
"random_device::"
1481 "random_device(const std::string&)"));
1485 { std::fclose(_M_file); }
1490 random_device(
const std::string& __token =
"mt19937")
1491 : _M_mt(_M_strtoul(__token)) { }
1494 static unsigned long
1497 unsigned long __ret = 5489UL;
1498 if (__str !=
"mt19937")
1500 const char* __nptr = __str.c_str();
1502 __ret = std::strtoul(__nptr, &__endptr, 0);
1503 if (*__nptr ==
'\0' || *__endptr !=
'\0')
1504 std::__throw_runtime_error(__N(
"random_device::_M_strtoul"
1505 "(const std::string&)"));
1529 #ifdef _GLIBCXX_USE_RANDOM_TR1
1531 std::fread(reinterpret_cast<void*>(&__ret),
sizeof(result_type),
1540 random_device(
const random_device&);
1541 void operator=(
const random_device&);
1543 #ifdef _GLIBCXX_USE_RANDOM_TR1
1569 template<
typename _IntType =
int>
1576 typedef _IntType input_type;
1578 typedef _IntType result_type;
1585 uniform_int(_IntType __min = 0, _IntType __max = 9)
1586 : _M_min(__min), _M_max(__max)
1617 template<
typename _UniformRandomNumberGenerator>
1619 operator()(_UniformRandomNumberGenerator& __urng)
1621 typedef typename _UniformRandomNumberGenerator::result_type
1623 return _M_call(__urng, _M_min, _M_max,
1624 typename is_integral<_UResult_type>::type());
1632 template<
typename _UniformRandomNumberGenerator>
1634 operator()(_UniformRandomNumberGenerator& __urng, result_type __n)
1636 typedef typename _UniformRandomNumberGenerator::result_type
1638 return _M_call(__urng, 0, __n - 1,
1639 typename is_integral<_UResult_type>::type());
1652 template<
typename _IntType1,
typename _CharT,
typename _Traits>
1653 friend std::basic_ostream<_CharT, _Traits>&
1654 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1655 const uniform_int<_IntType1>& __x);
1666 template<
typename _IntType1,
typename _CharT,
typename _Traits>
1667 friend std::basic_istream<_CharT, _Traits>&
1668 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1669 uniform_int<_IntType1>& __x);
1672 template<
typename _UniformRandomNumberGenerator>
1674 _M_call(_UniformRandomNumberGenerator& __urng,
1675 result_type __min, result_type __max,
true_type);
1677 template<
typename _UniformRandomNumberGenerator>
1679 _M_call(_UniformRandomNumberGenerator& __urng,
1680 result_type __min, result_type __max,
false_type)
1682 return result_type((__urng() - __urng.min())
1683 / (__urng.max() - __urng.min())
1684 * (__max - __min + 1)) + __min;
1698 class bernoulli_distribution
1701 typedef int input_type;
1702 typedef bool result_type;
1712 bernoulli_distribution(
double __p = 0.5)
1736 template<
class _UniformRandomNumberGenerator>
1738 operator()(_UniformRandomNumberGenerator& __urng)
1740 if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min()))
1755 template<
typename _CharT,
typename _Traits>
1756 friend std::basic_ostream<_CharT, _Traits>&
1757 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1758 const bernoulli_distribution& __x);
1769 template<
typename _CharT,
typename _Traits>
1770 friend std::basic_istream<_CharT, _Traits>&
1771 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1772 bernoulli_distribution& __x)
1773 {
return __is >> __x._M_p; }
1787 template<
typename _IntType =
int,
typename _RealType =
double>
1788 class geometric_distribution
1792 typedef _RealType input_type;
1793 typedef _IntType result_type;
1797 geometric_distribution(
const _RealType& __p = _RealType(0.5))
1814 template<
class _UniformRandomNumberGenerator>
1816 operator()(_UniformRandomNumberGenerator& __urng);
1828 template<
typename _IntType1,
typename _RealType1,
1829 typename _CharT,
typename _Traits>
1830 friend std::basic_ostream<_CharT, _Traits>&
1831 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1832 const geometric_distribution<_IntType1, _RealType1>& __x);
1843 template<
typename _CharT,
typename _Traits>
1844 friend std::basic_istream<_CharT, _Traits>&
1845 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1846 geometric_distribution& __x)
1849 __x._M_initialize();
1856 { _M_log_p = std::log(_M_p); }
1863 template<
typename _RealType>
1864 class normal_distribution;
1873 template<
typename _IntType =
int,
typename _RealType =
double>
1874 class poisson_distribution
1878 typedef _RealType input_type;
1879 typedef _IntType result_type;
1883 poisson_distribution(
const _RealType& __mean = _RealType(1))
1884 : _M_mean(__mean), _M_nd()
1901 template<
class _UniformRandomNumberGenerator>
1903 operator()(_UniformRandomNumberGenerator& __urng);
1915 template<
typename _IntType1,
typename _RealType1,
1916 typename _CharT,
typename _Traits>
1917 friend std::basic_ostream<_CharT, _Traits>&
1918 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1919 const poisson_distribution<_IntType1, _RealType1>& __x);
1930 template<
typename _IntType1,
typename _RealType1,
1931 typename _CharT,
typename _Traits>
1932 friend std::basic_istream<_CharT, _Traits>&
1933 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1934 poisson_distribution<_IntType1, _RealType1>& __x);
1941 normal_distribution<_RealType> _M_nd;
1946 _RealType _M_lm_thr;
1947 #if _GLIBCXX_USE_C99_MATH_TR1
1948 _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
1960 template<
typename _IntType =
int,
typename _RealType =
double>
1961 class binomial_distribution
1965 typedef _RealType input_type;
1966 typedef _IntType result_type;
1970 binomial_distribution(_IntType __t = 1,
1971 const _RealType& __p = _RealType(0.5))
1972 : _M_t(__t), _M_p(__p), _M_nd()
1996 template<
class _UniformRandomNumberGenerator>
1998 operator()(_UniformRandomNumberGenerator& __urng);
2010 template<
typename _IntType1,
typename _RealType1,
2011 typename _CharT,
typename _Traits>
2012 friend std::basic_ostream<_CharT, _Traits>&
2013 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2014 const binomial_distribution<_IntType1, _RealType1>& __x);
2025 template<
typename _IntType1,
typename _RealType1,
2026 typename _CharT,
typename _Traits>
2027 friend std::basic_istream<_CharT, _Traits>&
2028 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2029 binomial_distribution<_IntType1, _RealType1>& __x);
2035 template<
class _UniformRandomNumberGenerator>
2037 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
2040 normal_distribution<_RealType> _M_nd;
2043 #if _GLIBCXX_USE_C99_MATH_TR1
2044 _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
2045 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
2068 template<
typename _RealType =
double>
2073 typedef _RealType input_type;
2074 typedef _RealType result_type;
2084 uniform_real(_RealType __min = _RealType(0),
2085 _RealType __max = _RealType(1))
2086 : _M_min(__min), _M_max(__max)
2102 template<
class _UniformRandomNumberGenerator>
2104 operator()(_UniformRandomNumberGenerator& __urng)
2105 {
return (__urng() * (_M_max - _M_min)) + _M_min; }
2117 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2118 friend std::basic_ostream<_CharT, _Traits>&
2119 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2120 const uniform_real<_RealType1>& __x);
2131 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2132 friend std::basic_istream<_CharT, _Traits>&
2133 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2134 uniform_real<_RealType1>& __x);
2157 template<
typename _RealType =
double>
2158 class exponential_distribution
2162 typedef _RealType input_type;
2163 typedef _RealType result_type;
2171 exponential_distribution(
const result_type& __lambda = result_type(1))
2172 : _M_lambda(__lambda)
2182 {
return _M_lambda; }
2192 template<
class _UniformRandomNumberGenerator>
2194 operator()(_UniformRandomNumberGenerator& __urng)
2195 {
return -std::log(__urng()) / _M_lambda; }
2207 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2208 friend std::basic_ostream<_CharT, _Traits>&
2209 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2210 const exponential_distribution<_RealType1>& __x);
2222 template<
typename _CharT,
typename _Traits>
2223 friend std::basic_istream<_CharT, _Traits>&
2224 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2225 exponential_distribution& __x)
2226 {
return __is >> __x._M_lambda; }
2229 result_type _M_lambda;
2240 template<
typename _RealType =
double>
2241 class normal_distribution
2245 typedef _RealType input_type;
2246 typedef _RealType result_type;
2254 normal_distribution(
const result_type& __mean = result_type(0),
2255 const result_type& __sigma = result_type(1))
2256 : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(
false)
2273 {
return _M_sigma; }
2280 { _M_saved_available =
false; }
2282 template<
class _UniformRandomNumberGenerator>
2284 operator()(_UniformRandomNumberGenerator& __urng);
2296 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2297 friend std::basic_ostream<_CharT, _Traits>&
2298 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2299 const normal_distribution<_RealType1>& __x);
2310 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2311 friend std::basic_istream<_CharT, _Traits>&
2312 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2313 normal_distribution<_RealType1>& __x);
2316 result_type _M_mean;
2317 result_type _M_sigma;
2318 result_type _M_saved;
2319 bool _M_saved_available;
2329 template<
typename _RealType =
double>
2330 class gamma_distribution
2334 typedef _RealType input_type;
2335 typedef _RealType result_type;
2342 gamma_distribution(
const result_type& __alpha_val = result_type(1))
2343 : _M_alpha(__alpha_val)
2354 {
return _M_alpha; }
2362 template<
class _UniformRandomNumberGenerator>
2364 operator()(_UniformRandomNumberGenerator& __urng);
2376 template<
typename _RealType1,
typename _CharT,
typename _Traits>
2377 friend std::basic_ostream<_CharT, _Traits>&
2378 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2379 const gamma_distribution<_RealType1>& __x);
2390 template<
typename _CharT,
typename _Traits>
2391 friend std::basic_istream<_CharT, _Traits>&
2392 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2393 gamma_distribution& __x)
2395 __is >> __x._M_alpha;
2396 __x._M_initialize();
2404 result_type _M_alpha;
2413 _GLIBCXX_END_NAMESPACE_VERSION
2417 #endif // _GLIBCXX_TR1_RANDOM_H
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define false
Definition: stdbool.h:35
#define _GLIBCXX_DEBUG_ASSERT(_Condition)
Definition: debug.h:61
#define true
Definition: stdbool.h:34
#define __glibcxx_class_requires(_a, _b)
Definition: concept_check.h:48
basic_string< char > string
Definition: string:1153
const _Tp & min(const _Tp &__a, const _Tp &__b)
Equivalent to std::min.
Definition: base.h:144
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Allocator > &__str)
Definition: string:1122
namespace std _GLIBCXX_VISIBILITY(default)
Definition: auto_ptr.h:36
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
const _Tp & max(const _Tp &__a, const _Tp &__b)
Equivalent to std::max.
Definition: base.h:150
std::tr1::integral_constant< int, 1 > true_type
Definition: type_utils.hpp:70
std::tr1::integral_constant< int, 0 > false_type
Definition: type_utils.hpp:71