libstdc++
|
00001 // random number generation -*- C++ -*- 00002 00003 // Copyright (C) 2009-2018 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** 00026 * @file bits/random.h 00027 * This is an internal header file, included by other library headers. 00028 * Do not attempt to use it directly. @headername{random} 00029 */ 00030 00031 #ifndef _RANDOM_H 00032 #define _RANDOM_H 1 00033 00034 #include <vector> 00035 #include <bits/uniform_int_dist.h> 00036 00037 namespace std _GLIBCXX_VISIBILITY(default) 00038 { 00039 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00040 00041 // [26.4] Random number generation 00042 00043 /** 00044 * @defgroup random Random Number Generation 00045 * @ingroup numerics 00046 * 00047 * A facility for generating random numbers on selected distributions. 00048 * @{ 00049 */ 00050 00051 /** 00052 * @brief A function template for converting the output of a (integral) 00053 * uniform random number generator to a floatng point result in the range 00054 * [0-1). 00055 */ 00056 template<typename _RealType, size_t __bits, 00057 typename _UniformRandomNumberGenerator> 00058 _RealType 00059 generate_canonical(_UniformRandomNumberGenerator& __g); 00060 00061 /* 00062 * Implementation-space details. 00063 */ 00064 namespace __detail 00065 { 00066 template<typename _UIntType, size_t __w, 00067 bool = __w < static_cast<size_t> 00068 (std::numeric_limits<_UIntType>::digits)> 00069 struct _Shift 00070 { static const _UIntType __value = 0; }; 00071 00072 template<typename _UIntType, size_t __w> 00073 struct _Shift<_UIntType, __w, true> 00074 { static const _UIntType __value = _UIntType(1) << __w; }; 00075 00076 template<int __s, 00077 int __which = ((__s <= __CHAR_BIT__ * sizeof (int)) 00078 + (__s <= __CHAR_BIT__ * sizeof (long)) 00079 + (__s <= __CHAR_BIT__ * sizeof (long long)) 00080 /* assume long long no bigger than __int128 */ 00081 + (__s <= 128))> 00082 struct _Select_uint_least_t 00083 { 00084 static_assert(__which < 0, /* needs to be dependent */ 00085 "sorry, would be too much trouble for a slow result"); 00086 }; 00087 00088 template<int __s> 00089 struct _Select_uint_least_t<__s, 4> 00090 { typedef unsigned int type; }; 00091 00092 template<int __s> 00093 struct _Select_uint_least_t<__s, 3> 00094 { typedef unsigned long type; }; 00095 00096 template<int __s> 00097 struct _Select_uint_least_t<__s, 2> 00098 { typedef unsigned long long type; }; 00099 00100 #ifdef _GLIBCXX_USE_INT128 00101 template<int __s> 00102 struct _Select_uint_least_t<__s, 1> 00103 { typedef unsigned __int128 type; }; 00104 #endif 00105 00106 // Assume a != 0, a < m, c < m, x < m. 00107 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, 00108 bool __big_enough = (!(__m & (__m - 1)) 00109 || (_Tp(-1) - __c) / __a >= __m - 1), 00110 bool __schrage_ok = __m % __a < __m / __a> 00111 struct _Mod 00112 { 00113 typedef typename _Select_uint_least_t<std::__lg(__a) 00114 + std::__lg(__m) + 2>::type _Tp2; 00115 static _Tp 00116 __calc(_Tp __x) 00117 { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); } 00118 }; 00119 00120 // Schrage. 00121 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c> 00122 struct _Mod<_Tp, __m, __a, __c, false, true> 00123 { 00124 static _Tp 00125 __calc(_Tp __x); 00126 }; 00127 00128 // Special cases: 00129 // - for m == 2^n or m == 0, unsigned integer overflow is safe. 00130 // - a * (m - 1) + c fits in _Tp, there is no overflow. 00131 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s> 00132 struct _Mod<_Tp, __m, __a, __c, true, __s> 00133 { 00134 static _Tp 00135 __calc(_Tp __x) 00136 { 00137 _Tp __res = __a * __x + __c; 00138 if (__m) 00139 __res %= __m; 00140 return __res; 00141 } 00142 }; 00143 00144 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0> 00145 inline _Tp 00146 __mod(_Tp __x) 00147 { return _Mod<_Tp, __m, __a, __c>::__calc(__x); } 00148 00149 /* 00150 * An adaptor class for converting the output of any Generator into 00151 * the input for a specific Distribution. 00152 */ 00153 template<typename _Engine, typename _DInputType> 00154 struct _Adaptor 00155 { 00156 static_assert(std::is_floating_point<_DInputType>::value, 00157 "template argument must be a floating point type"); 00158 00159 public: 00160 _Adaptor(_Engine& __g) 00161 : _M_g(__g) { } 00162 00163 _DInputType 00164 min() const 00165 { return _DInputType(0); } 00166 00167 _DInputType 00168 max() const 00169 { return _DInputType(1); } 00170 00171 /* 00172 * Converts a value generated by the adapted random number generator 00173 * into a value in the input domain for the dependent random number 00174 * distribution. 00175 */ 00176 _DInputType 00177 operator()() 00178 { 00179 return std::generate_canonical<_DInputType, 00180 std::numeric_limits<_DInputType>::digits, 00181 _Engine>(_M_g); 00182 } 00183 00184 private: 00185 _Engine& _M_g; 00186 }; 00187 00188 } // namespace __detail 00189 00190 /** 00191 * @addtogroup random_generators Random Number Generators 00192 * @ingroup random 00193 * 00194 * These classes define objects which provide random or pseudorandom 00195 * numbers, either from a discrete or a continuous interval. The 00196 * random number generator supplied as a part of this library are 00197 * all uniform random number generators which provide a sequence of 00198 * random number uniformly distributed over their range. 00199 * 00200 * A number generator is a function object with an operator() that 00201 * takes zero arguments and returns a number. 00202 * 00203 * A compliant random number generator must satisfy the following 00204 * requirements. <table border=1 cellpadding=10 cellspacing=0> 00205 * <caption align=top>Random Number Generator Requirements</caption> 00206 * <tr><td>To be documented.</td></tr> </table> 00207 * 00208 * @{ 00209 */ 00210 00211 /** 00212 * @brief A model of a linear congruential random number generator. 00213 * 00214 * A random number generator that produces pseudorandom numbers via 00215 * linear function: 00216 * @f[ 00217 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m 00218 * @f] 00219 * 00220 * The template parameter @p _UIntType must be an unsigned integral type 00221 * large enough to store values up to (__m-1). If the template parameter 00222 * @p __m is 0, the modulus @p __m used is 00223 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template 00224 * parameters @p __a and @p __c must be less than @p __m. 00225 * 00226 * The size of the state is @f$1@f$. 00227 */ 00228 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 00229 class linear_congruential_engine 00230 { 00231 static_assert(std::is_unsigned<_UIntType>::value, 00232 "result_type must be an unsigned integral type"); 00233 static_assert(__m == 0u || (__a < __m && __c < __m), 00234 "template argument substituting __m out of bounds"); 00235 00236 public: 00237 /** The type of the generated random value. */ 00238 typedef _UIntType result_type; 00239 00240 /** The multiplier. */ 00241 static constexpr result_type multiplier = __a; 00242 /** An increment. */ 00243 static constexpr result_type increment = __c; 00244 /** The modulus. */ 00245 static constexpr result_type modulus = __m; 00246 static constexpr result_type default_seed = 1u; 00247 00248 /** 00249 * @brief Constructs a %linear_congruential_engine random number 00250 * generator engine with seed @p __s. The default seed value 00251 * is 1. 00252 * 00253 * @param __s The initial seed value. 00254 */ 00255 explicit 00256 linear_congruential_engine(result_type __s = default_seed) 00257 { seed(__s); } 00258 00259 /** 00260 * @brief Constructs a %linear_congruential_engine random number 00261 * generator engine seeded from the seed sequence @p __q. 00262 * 00263 * @param __q the seed sequence. 00264 */ 00265 template<typename _Sseq, typename = typename 00266 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value> 00267 ::type> 00268 explicit 00269 linear_congruential_engine(_Sseq& __q) 00270 { seed(__q); } 00271 00272 /** 00273 * @brief Reseeds the %linear_congruential_engine random number generator 00274 * engine sequence to the seed @p __s. 00275 * 00276 * @param __s The new seed. 00277 */ 00278 void 00279 seed(result_type __s = default_seed); 00280 00281 /** 00282 * @brief Reseeds the %linear_congruential_engine random number generator 00283 * engine 00284 * sequence using values from the seed sequence @p __q. 00285 * 00286 * @param __q the seed sequence. 00287 */ 00288 template<typename _Sseq> 00289 typename std::enable_if<std::is_class<_Sseq>::value>::type 00290 seed(_Sseq& __q); 00291 00292 /** 00293 * @brief Gets the smallest possible value in the output range. 00294 * 00295 * The minimum depends on the @p __c parameter: if it is zero, the 00296 * minimum generated must be > 0, otherwise 0 is allowed. 00297 */ 00298 static constexpr result_type 00299 min() 00300 { return __c == 0u ? 1u : 0u; } 00301 00302 /** 00303 * @brief Gets the largest possible value in the output range. 00304 */ 00305 static constexpr result_type 00306 max() 00307 { return __m - 1u; } 00308 00309 /** 00310 * @brief Discard a sequence of random numbers. 00311 */ 00312 void 00313 discard(unsigned long long __z) 00314 { 00315 for (; __z != 0ULL; --__z) 00316 (*this)(); 00317 } 00318 00319 /** 00320 * @brief Gets the next random number in the sequence. 00321 */ 00322 result_type 00323 operator()() 00324 { 00325 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x); 00326 return _M_x; 00327 } 00328 00329 /** 00330 * @brief Compares two linear congruential random number generator 00331 * objects of the same type for equality. 00332 * 00333 * @param __lhs A linear congruential random number generator object. 00334 * @param __rhs Another linear congruential random number generator 00335 * object. 00336 * 00337 * @returns true if the infinite sequences of generated values 00338 * would be equal, false otherwise. 00339 */ 00340 friend bool 00341 operator==(const linear_congruential_engine& __lhs, 00342 const linear_congruential_engine& __rhs) 00343 { return __lhs._M_x == __rhs._M_x; } 00344 00345 /** 00346 * @brief Writes the textual representation of the state x(i) of x to 00347 * @p __os. 00348 * 00349 * @param __os The output stream. 00350 * @param __lcr A % linear_congruential_engine random number generator. 00351 * @returns __os. 00352 */ 00353 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, 00354 _UIntType1 __m1, typename _CharT, typename _Traits> 00355 friend std::basic_ostream<_CharT, _Traits>& 00356 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00357 const std::linear_congruential_engine<_UIntType1, 00358 __a1, __c1, __m1>& __lcr); 00359 00360 /** 00361 * @brief Sets the state of the engine by reading its textual 00362 * representation from @p __is. 00363 * 00364 * The textual representation must have been previously written using 00365 * an output stream whose imbued locale and whose type's template 00366 * specialization arguments _CharT and _Traits were the same as those 00367 * of @p __is. 00368 * 00369 * @param __is The input stream. 00370 * @param __lcr A % linear_congruential_engine random number generator. 00371 * @returns __is. 00372 */ 00373 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, 00374 _UIntType1 __m1, typename _CharT, typename _Traits> 00375 friend std::basic_istream<_CharT, _Traits>& 00376 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00377 std::linear_congruential_engine<_UIntType1, __a1, 00378 __c1, __m1>& __lcr); 00379 00380 private: 00381 _UIntType _M_x; 00382 }; 00383 00384 /** 00385 * @brief Compares two linear congruential random number generator 00386 * objects of the same type for inequality. 00387 * 00388 * @param __lhs A linear congruential random number generator object. 00389 * @param __rhs Another linear congruential random number generator 00390 * object. 00391 * 00392 * @returns true if the infinite sequences of generated values 00393 * would be different, false otherwise. 00394 */ 00395 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 00396 inline bool 00397 operator!=(const std::linear_congruential_engine<_UIntType, __a, 00398 __c, __m>& __lhs, 00399 const std::linear_congruential_engine<_UIntType, __a, 00400 __c, __m>& __rhs) 00401 { return !(__lhs == __rhs); } 00402 00403 00404 /** 00405 * A generalized feedback shift register discrete random number generator. 00406 * 00407 * This algorithm avoids multiplication and division and is designed to be 00408 * friendly to a pipelined architecture. If the parameters are chosen 00409 * correctly, this generator will produce numbers with a very long period and 00410 * fairly good apparent entropy, although still not cryptographically strong. 00411 * 00412 * The best way to use this generator is with the predefined mt19937 class. 00413 * 00414 * This algorithm was originally invented by Makoto Matsumoto and 00415 * Takuji Nishimura. 00416 * 00417 * @tparam __w Word size, the number of bits in each element of 00418 * the state vector. 00419 * @tparam __n The degree of recursion. 00420 * @tparam __m The period parameter. 00421 * @tparam __r The separation point bit index. 00422 * @tparam __a The last row of the twist matrix. 00423 * @tparam __u The first right-shift tempering matrix parameter. 00424 * @tparam __d The first right-shift tempering matrix mask. 00425 * @tparam __s The first left-shift tempering matrix parameter. 00426 * @tparam __b The first left-shift tempering matrix mask. 00427 * @tparam __t The second left-shift tempering matrix parameter. 00428 * @tparam __c The second left-shift tempering matrix mask. 00429 * @tparam __l The second right-shift tempering matrix parameter. 00430 * @tparam __f Initialization multiplier. 00431 */ 00432 template<typename _UIntType, size_t __w, 00433 size_t __n, size_t __m, size_t __r, 00434 _UIntType __a, size_t __u, _UIntType __d, size_t __s, 00435 _UIntType __b, size_t __t, 00436 _UIntType __c, size_t __l, _UIntType __f> 00437 class mersenne_twister_engine 00438 { 00439 static_assert(std::is_unsigned<_UIntType>::value, 00440 "result_type must be an unsigned integral type"); 00441 static_assert(1u <= __m && __m <= __n, 00442 "template argument substituting __m out of bounds"); 00443 static_assert(__r <= __w, "template argument substituting " 00444 "__r out of bound"); 00445 static_assert(__u <= __w, "template argument substituting " 00446 "__u out of bound"); 00447 static_assert(__s <= __w, "template argument substituting " 00448 "__s out of bound"); 00449 static_assert(__t <= __w, "template argument substituting " 00450 "__t out of bound"); 00451 static_assert(__l <= __w, "template argument substituting " 00452 "__l out of bound"); 00453 static_assert(__w <= std::numeric_limits<_UIntType>::digits, 00454 "template argument substituting __w out of bound"); 00455 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1), 00456 "template argument substituting __a out of bound"); 00457 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1), 00458 "template argument substituting __b out of bound"); 00459 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1), 00460 "template argument substituting __c out of bound"); 00461 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1), 00462 "template argument substituting __d out of bound"); 00463 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1), 00464 "template argument substituting __f out of bound"); 00465 00466 public: 00467 /** The type of the generated random value. */ 00468 typedef _UIntType result_type; 00469 00470 // parameter values 00471 static constexpr size_t word_size = __w; 00472 static constexpr size_t state_size = __n; 00473 static constexpr size_t shift_size = __m; 00474 static constexpr size_t mask_bits = __r; 00475 static constexpr result_type xor_mask = __a; 00476 static constexpr size_t tempering_u = __u; 00477 static constexpr result_type tempering_d = __d; 00478 static constexpr size_t tempering_s = __s; 00479 static constexpr result_type tempering_b = __b; 00480 static constexpr size_t tempering_t = __t; 00481 static constexpr result_type tempering_c = __c; 00482 static constexpr size_t tempering_l = __l; 00483 static constexpr result_type initialization_multiplier = __f; 00484 static constexpr result_type default_seed = 5489u; 00485 00486 // constructors and member function 00487 explicit 00488 mersenne_twister_engine(result_type __sd = default_seed) 00489 { seed(__sd); } 00490 00491 /** 00492 * @brief Constructs a %mersenne_twister_engine random number generator 00493 * engine seeded from the seed sequence @p __q. 00494 * 00495 * @param __q the seed sequence. 00496 */ 00497 template<typename _Sseq, typename = typename 00498 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value> 00499 ::type> 00500 explicit 00501 mersenne_twister_engine(_Sseq& __q) 00502 { seed(__q); } 00503 00504 void 00505 seed(result_type __sd = default_seed); 00506 00507 template<typename _Sseq> 00508 typename std::enable_if<std::is_class<_Sseq>::value>::type 00509 seed(_Sseq& __q); 00510 00511 /** 00512 * @brief Gets the smallest possible value in the output range. 00513 */ 00514 static constexpr result_type 00515 min() 00516 { return 0; } 00517 00518 /** 00519 * @brief Gets the largest possible value in the output range. 00520 */ 00521 static constexpr result_type 00522 max() 00523 { return __detail::_Shift<_UIntType, __w>::__value - 1; } 00524 00525 /** 00526 * @brief Discard a sequence of random numbers. 00527 */ 00528 void 00529 discard(unsigned long long __z); 00530 00531 result_type 00532 operator()(); 00533 00534 /** 00535 * @brief Compares two % mersenne_twister_engine random number generator 00536 * objects of the same type for equality. 00537 * 00538 * @param __lhs A % mersenne_twister_engine random number generator 00539 * object. 00540 * @param __rhs Another % mersenne_twister_engine random number 00541 * generator object. 00542 * 00543 * @returns true if the infinite sequences of generated values 00544 * would be equal, false otherwise. 00545 */ 00546 friend bool 00547 operator==(const mersenne_twister_engine& __lhs, 00548 const mersenne_twister_engine& __rhs) 00549 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x) 00550 && __lhs._M_p == __rhs._M_p); } 00551 00552 /** 00553 * @brief Inserts the current state of a % mersenne_twister_engine 00554 * random number generator engine @p __x into the output stream 00555 * @p __os. 00556 * 00557 * @param __os An output stream. 00558 * @param __x A % mersenne_twister_engine random number generator 00559 * engine. 00560 * 00561 * @returns The output stream with the state of @p __x inserted or in 00562 * an error state. 00563 */ 00564 template<typename _UIntType1, 00565 size_t __w1, size_t __n1, 00566 size_t __m1, size_t __r1, 00567 _UIntType1 __a1, size_t __u1, 00568 _UIntType1 __d1, size_t __s1, 00569 _UIntType1 __b1, size_t __t1, 00570 _UIntType1 __c1, size_t __l1, _UIntType1 __f1, 00571 typename _CharT, typename _Traits> 00572 friend std::basic_ostream<_CharT, _Traits>& 00573 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00574 const std::mersenne_twister_engine<_UIntType1, __w1, __n1, 00575 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, 00576 __l1, __f1>& __x); 00577 00578 /** 00579 * @brief Extracts the current state of a % mersenne_twister_engine 00580 * random number generator engine @p __x from the input stream 00581 * @p __is. 00582 * 00583 * @param __is An input stream. 00584 * @param __x A % mersenne_twister_engine random number generator 00585 * engine. 00586 * 00587 * @returns The input stream with the state of @p __x extracted or in 00588 * an error state. 00589 */ 00590 template<typename _UIntType1, 00591 size_t __w1, size_t __n1, 00592 size_t __m1, size_t __r1, 00593 _UIntType1 __a1, size_t __u1, 00594 _UIntType1 __d1, size_t __s1, 00595 _UIntType1 __b1, size_t __t1, 00596 _UIntType1 __c1, size_t __l1, _UIntType1 __f1, 00597 typename _CharT, typename _Traits> 00598 friend std::basic_istream<_CharT, _Traits>& 00599 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00600 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, 00601 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, 00602 __l1, __f1>& __x); 00603 00604 private: 00605 void _M_gen_rand(); 00606 00607 _UIntType _M_x[state_size]; 00608 size_t _M_p; 00609 }; 00610 00611 /** 00612 * @brief Compares two % mersenne_twister_engine random number generator 00613 * objects of the same type for inequality. 00614 * 00615 * @param __lhs A % mersenne_twister_engine random number generator 00616 * object. 00617 * @param __rhs Another % mersenne_twister_engine random number 00618 * generator object. 00619 * 00620 * @returns true if the infinite sequences of generated values 00621 * would be different, false otherwise. 00622 */ 00623 template<typename _UIntType, size_t __w, 00624 size_t __n, size_t __m, size_t __r, 00625 _UIntType __a, size_t __u, _UIntType __d, size_t __s, 00626 _UIntType __b, size_t __t, 00627 _UIntType __c, size_t __l, _UIntType __f> 00628 inline bool 00629 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m, 00630 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs, 00631 const std::mersenne_twister_engine<_UIntType, __w, __n, __m, 00632 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs) 00633 { return !(__lhs == __rhs); } 00634 00635 00636 /** 00637 * @brief The Marsaglia-Zaman generator. 00638 * 00639 * This is a model of a Generalized Fibonacci discrete random number 00640 * generator, sometimes referred to as the SWC generator. 00641 * 00642 * A discrete random number generator that produces pseudorandom 00643 * numbers using: 00644 * @f[ 00645 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m 00646 * @f] 00647 * 00648 * The size of the state is @f$r@f$ 00649 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$. 00650 */ 00651 template<typename _UIntType, size_t __w, size_t __s, size_t __r> 00652 class subtract_with_carry_engine 00653 { 00654 static_assert(std::is_unsigned<_UIntType>::value, 00655 "result_type must be an unsigned integral type"); 00656 static_assert(0u < __s && __s < __r, 00657 "0 < s < r"); 00658 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits, 00659 "template argument substituting __w out of bounds"); 00660 00661 public: 00662 /** The type of the generated random value. */ 00663 typedef _UIntType result_type; 00664 00665 // parameter values 00666 static constexpr size_t word_size = __w; 00667 static constexpr size_t short_lag = __s; 00668 static constexpr size_t long_lag = __r; 00669 static constexpr result_type default_seed = 19780503u; 00670 00671 /** 00672 * @brief Constructs an explicitly seeded % subtract_with_carry_engine 00673 * random number generator. 00674 */ 00675 explicit 00676 subtract_with_carry_engine(result_type __sd = default_seed) 00677 { seed(__sd); } 00678 00679 /** 00680 * @brief Constructs a %subtract_with_carry_engine random number engine 00681 * seeded from the seed sequence @p __q. 00682 * 00683 * @param __q the seed sequence. 00684 */ 00685 template<typename _Sseq, typename = typename 00686 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value> 00687 ::type> 00688 explicit 00689 subtract_with_carry_engine(_Sseq& __q) 00690 { seed(__q); } 00691 00692 /** 00693 * @brief Seeds the initial state @f$x_0@f$ of the random number 00694 * generator. 00695 * 00696 * N1688[4.19] modifies this as follows. If @p __value == 0, 00697 * sets value to 19780503. In any case, with a linear 00698 * congruential generator lcg(i) having parameters @f$ m_{lcg} = 00699 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value 00700 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m 00701 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ 00702 * set carry to 1, otherwise sets carry to 0. 00703 */ 00704 void 00705 seed(result_type __sd = default_seed); 00706 00707 /** 00708 * @brief Seeds the initial state @f$x_0@f$ of the 00709 * % subtract_with_carry_engine random number generator. 00710 */ 00711 template<typename _Sseq> 00712 typename std::enable_if<std::is_class<_Sseq>::value>::type 00713 seed(_Sseq& __q); 00714 00715 /** 00716 * @brief Gets the inclusive minimum value of the range of random 00717 * integers returned by this generator. 00718 */ 00719 static constexpr result_type 00720 min() 00721 { return 0; } 00722 00723 /** 00724 * @brief Gets the inclusive maximum value of the range of random 00725 * integers returned by this generator. 00726 */ 00727 static constexpr result_type 00728 max() 00729 { return __detail::_Shift<_UIntType, __w>::__value - 1; } 00730 00731 /** 00732 * @brief Discard a sequence of random numbers. 00733 */ 00734 void 00735 discard(unsigned long long __z) 00736 { 00737 for (; __z != 0ULL; --__z) 00738 (*this)(); 00739 } 00740 00741 /** 00742 * @brief Gets the next random number in the sequence. 00743 */ 00744 result_type 00745 operator()(); 00746 00747 /** 00748 * @brief Compares two % subtract_with_carry_engine random number 00749 * generator objects of the same type for equality. 00750 * 00751 * @param __lhs A % subtract_with_carry_engine random number generator 00752 * object. 00753 * @param __rhs Another % subtract_with_carry_engine random number 00754 * generator object. 00755 * 00756 * @returns true if the infinite sequences of generated values 00757 * would be equal, false otherwise. 00758 */ 00759 friend bool 00760 operator==(const subtract_with_carry_engine& __lhs, 00761 const subtract_with_carry_engine& __rhs) 00762 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x) 00763 && __lhs._M_carry == __rhs._M_carry 00764 && __lhs._M_p == __rhs._M_p); } 00765 00766 /** 00767 * @brief Inserts the current state of a % subtract_with_carry_engine 00768 * random number generator engine @p __x into the output stream 00769 * @p __os. 00770 * 00771 * @param __os An output stream. 00772 * @param __x A % subtract_with_carry_engine random number generator 00773 * engine. 00774 * 00775 * @returns The output stream with the state of @p __x inserted or in 00776 * an error state. 00777 */ 00778 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, 00779 typename _CharT, typename _Traits> 00780 friend std::basic_ostream<_CharT, _Traits>& 00781 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00782 const std::subtract_with_carry_engine<_UIntType1, __w1, 00783 __s1, __r1>& __x); 00784 00785 /** 00786 * @brief Extracts the current state of a % subtract_with_carry_engine 00787 * random number generator engine @p __x from the input stream 00788 * @p __is. 00789 * 00790 * @param __is An input stream. 00791 * @param __x A % subtract_with_carry_engine random number generator 00792 * engine. 00793 * 00794 * @returns The input stream with the state of @p __x extracted or in 00795 * an error state. 00796 */ 00797 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, 00798 typename _CharT, typename _Traits> 00799 friend std::basic_istream<_CharT, _Traits>& 00800 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00801 std::subtract_with_carry_engine<_UIntType1, __w1, 00802 __s1, __r1>& __x); 00803 00804 private: 00805 /// The state of the generator. This is a ring buffer. 00806 _UIntType _M_x[long_lag]; 00807 _UIntType _M_carry; ///< The carry 00808 size_t _M_p; ///< Current index of x(i - r). 00809 }; 00810 00811 /** 00812 * @brief Compares two % subtract_with_carry_engine random number 00813 * generator objects of the same type for inequality. 00814 * 00815 * @param __lhs A % subtract_with_carry_engine random number generator 00816 * object. 00817 * @param __rhs Another % subtract_with_carry_engine random number 00818 * generator object. 00819 * 00820 * @returns true if the infinite sequences of generated values 00821 * would be different, false otherwise. 00822 */ 00823 template<typename _UIntType, size_t __w, size_t __s, size_t __r> 00824 inline bool 00825 operator!=(const std::subtract_with_carry_engine<_UIntType, __w, 00826 __s, __r>& __lhs, 00827 const std::subtract_with_carry_engine<_UIntType, __w, 00828 __s, __r>& __rhs) 00829 { return !(__lhs == __rhs); } 00830 00831 00832 /** 00833 * Produces random numbers from some base engine by discarding blocks of 00834 * data. 00835 * 00836 * 0 <= @p __r <= @p __p 00837 */ 00838 template<typename _RandomNumberEngine, size_t __p, size_t __r> 00839 class discard_block_engine 00840 { 00841 static_assert(1 <= __r && __r <= __p, 00842 "template argument substituting __r out of bounds"); 00843 00844 public: 00845 /** The type of the generated random value. */ 00846 typedef typename _RandomNumberEngine::result_type result_type; 00847 00848 // parameter values 00849 static constexpr size_t block_size = __p; 00850 static constexpr size_t used_block = __r; 00851 00852 /** 00853 * @brief Constructs a default %discard_block_engine engine. 00854 * 00855 * The underlying engine is default constructed as well. 00856 */ 00857 discard_block_engine() 00858 : _M_b(), _M_n(0) { } 00859 00860 /** 00861 * @brief Copy constructs a %discard_block_engine engine. 00862 * 00863 * Copies an existing base class random number generator. 00864 * @param __rng An existing (base class) engine object. 00865 */ 00866 explicit 00867 discard_block_engine(const _RandomNumberEngine& __rng) 00868 : _M_b(__rng), _M_n(0) { } 00869 00870 /** 00871 * @brief Move constructs a %discard_block_engine engine. 00872 * 00873 * Copies an existing base class random number generator. 00874 * @param __rng An existing (base class) engine object. 00875 */ 00876 explicit 00877 discard_block_engine(_RandomNumberEngine&& __rng) 00878 : _M_b(std::move(__rng)), _M_n(0) { } 00879 00880 /** 00881 * @brief Seed constructs a %discard_block_engine engine. 00882 * 00883 * Constructs the underlying generator engine seeded with @p __s. 00884 * @param __s A seed value for the base class engine. 00885 */ 00886 explicit 00887 discard_block_engine(result_type __s) 00888 : _M_b(__s), _M_n(0) { } 00889 00890 /** 00891 * @brief Generator construct a %discard_block_engine engine. 00892 * 00893 * @param __q A seed sequence. 00894 */ 00895 template<typename _Sseq, typename = typename 00896 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value 00897 && !std::is_same<_Sseq, _RandomNumberEngine>::value> 00898 ::type> 00899 explicit 00900 discard_block_engine(_Sseq& __q) 00901 : _M_b(__q), _M_n(0) 00902 { } 00903 00904 /** 00905 * @brief Reseeds the %discard_block_engine object with the default 00906 * seed for the underlying base class generator engine. 00907 */ 00908 void 00909 seed() 00910 { 00911 _M_b.seed(); 00912 _M_n = 0; 00913 } 00914 00915 /** 00916 * @brief Reseeds the %discard_block_engine object with the default 00917 * seed for the underlying base class generator engine. 00918 */ 00919 void 00920 seed(result_type __s) 00921 { 00922 _M_b.seed(__s); 00923 _M_n = 0; 00924 } 00925 00926 /** 00927 * @brief Reseeds the %discard_block_engine object with the given seed 00928 * sequence. 00929 * @param __q A seed generator function. 00930 */ 00931 template<typename _Sseq> 00932 void 00933 seed(_Sseq& __q) 00934 { 00935 _M_b.seed(__q); 00936 _M_n = 0; 00937 } 00938 00939 /** 00940 * @brief Gets a const reference to the underlying generator engine 00941 * object. 00942 */ 00943 const _RandomNumberEngine& 00944 base() const noexcept 00945 { return _M_b; } 00946 00947 /** 00948 * @brief Gets the minimum value in the generated random number range. 00949 */ 00950 static constexpr result_type 00951 min() 00952 { return _RandomNumberEngine::min(); } 00953 00954 /** 00955 * @brief Gets the maximum value in the generated random number range. 00956 */ 00957 static constexpr result_type 00958 max() 00959 { return _RandomNumberEngine::max(); } 00960 00961 /** 00962 * @brief Discard a sequence of random numbers. 00963 */ 00964 void 00965 discard(unsigned long long __z) 00966 { 00967 for (; __z != 0ULL; --__z) 00968 (*this)(); 00969 } 00970 00971 /** 00972 * @brief Gets the next value in the generated random number sequence. 00973 */ 00974 result_type 00975 operator()(); 00976 00977 /** 00978 * @brief Compares two %discard_block_engine random number generator 00979 * objects of the same type for equality. 00980 * 00981 * @param __lhs A %discard_block_engine random number generator object. 00982 * @param __rhs Another %discard_block_engine random number generator 00983 * object. 00984 * 00985 * @returns true if the infinite sequences of generated values 00986 * would be equal, false otherwise. 00987 */ 00988 friend bool 00989 operator==(const discard_block_engine& __lhs, 00990 const discard_block_engine& __rhs) 00991 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; } 00992 00993 /** 00994 * @brief Inserts the current state of a %discard_block_engine random 00995 * number generator engine @p __x into the output stream 00996 * @p __os. 00997 * 00998 * @param __os An output stream. 00999 * @param __x A %discard_block_engine random number generator engine. 01000 * 01001 * @returns The output stream with the state of @p __x inserted or in 01002 * an error state. 01003 */ 01004 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, 01005 typename _CharT, typename _Traits> 01006 friend std::basic_ostream<_CharT, _Traits>& 01007 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01008 const std::discard_block_engine<_RandomNumberEngine1, 01009 __p1, __r1>& __x); 01010 01011 /** 01012 * @brief Extracts the current state of a % subtract_with_carry_engine 01013 * random number generator engine @p __x from the input stream 01014 * @p __is. 01015 * 01016 * @param __is An input stream. 01017 * @param __x A %discard_block_engine random number generator engine. 01018 * 01019 * @returns The input stream with the state of @p __x extracted or in 01020 * an error state. 01021 */ 01022 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, 01023 typename _CharT, typename _Traits> 01024 friend std::basic_istream<_CharT, _Traits>& 01025 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01026 std::discard_block_engine<_RandomNumberEngine1, 01027 __p1, __r1>& __x); 01028 01029 private: 01030 _RandomNumberEngine _M_b; 01031 size_t _M_n; 01032 }; 01033 01034 /** 01035 * @brief Compares two %discard_block_engine random number generator 01036 * objects of the same type for inequality. 01037 * 01038 * @param __lhs A %discard_block_engine random number generator object. 01039 * @param __rhs Another %discard_block_engine random number generator 01040 * object. 01041 * 01042 * @returns true if the infinite sequences of generated values 01043 * would be different, false otherwise. 01044 */ 01045 template<typename _RandomNumberEngine, size_t __p, size_t __r> 01046 inline bool 01047 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p, 01048 __r>& __lhs, 01049 const std::discard_block_engine<_RandomNumberEngine, __p, 01050 __r>& __rhs) 01051 { return !(__lhs == __rhs); } 01052 01053 01054 /** 01055 * Produces random numbers by combining random numbers from some base 01056 * engine to produce random numbers with a specifies number of bits @p __w. 01057 */ 01058 template<typename _RandomNumberEngine, size_t __w, typename _UIntType> 01059 class independent_bits_engine 01060 { 01061 static_assert(std::is_unsigned<_UIntType>::value, 01062 "result_type must be an unsigned integral type"); 01063 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits, 01064 "template argument substituting __w out of bounds"); 01065 01066 public: 01067 /** The type of the generated random value. */ 01068 typedef _UIntType result_type; 01069 01070 /** 01071 * @brief Constructs a default %independent_bits_engine engine. 01072 * 01073 * The underlying engine is default constructed as well. 01074 */ 01075 independent_bits_engine() 01076 : _M_b() { } 01077 01078 /** 01079 * @brief Copy constructs a %independent_bits_engine engine. 01080 * 01081 * Copies an existing base class random number generator. 01082 * @param __rng An existing (base class) engine object. 01083 */ 01084 explicit 01085 independent_bits_engine(const _RandomNumberEngine& __rng) 01086 : _M_b(__rng) { } 01087 01088 /** 01089 * @brief Move constructs a %independent_bits_engine engine. 01090 * 01091 * Copies an existing base class random number generator. 01092 * @param __rng An existing (base class) engine object. 01093 */ 01094 explicit 01095 independent_bits_engine(_RandomNumberEngine&& __rng) 01096 : _M_b(std::move(__rng)) { } 01097 01098 /** 01099 * @brief Seed constructs a %independent_bits_engine engine. 01100 * 01101 * Constructs the underlying generator engine seeded with @p __s. 01102 * @param __s A seed value for the base class engine. 01103 */ 01104 explicit 01105 independent_bits_engine(result_type __s) 01106 : _M_b(__s) { } 01107 01108 /** 01109 * @brief Generator construct a %independent_bits_engine engine. 01110 * 01111 * @param __q A seed sequence. 01112 */ 01113 template<typename _Sseq, typename = typename 01114 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value 01115 && !std::is_same<_Sseq, _RandomNumberEngine>::value> 01116 ::type> 01117 explicit 01118 independent_bits_engine(_Sseq& __q) 01119 : _M_b(__q) 01120 { } 01121 01122 /** 01123 * @brief Reseeds the %independent_bits_engine object with the default 01124 * seed for the underlying base class generator engine. 01125 */ 01126 void 01127 seed() 01128 { _M_b.seed(); } 01129 01130 /** 01131 * @brief Reseeds the %independent_bits_engine object with the default 01132 * seed for the underlying base class generator engine. 01133 */ 01134 void 01135 seed(result_type __s) 01136 { _M_b.seed(__s); } 01137 01138 /** 01139 * @brief Reseeds the %independent_bits_engine object with the given 01140 * seed sequence. 01141 * @param __q A seed generator function. 01142 */ 01143 template<typename _Sseq> 01144 void 01145 seed(_Sseq& __q) 01146 { _M_b.seed(__q); } 01147 01148 /** 01149 * @brief Gets a const reference to the underlying generator engine 01150 * object. 01151 */ 01152 const _RandomNumberEngine& 01153 base() const noexcept 01154 { return _M_b; } 01155 01156 /** 01157 * @brief Gets the minimum value in the generated random number range. 01158 */ 01159 static constexpr result_type 01160 min() 01161 { return 0U; } 01162 01163 /** 01164 * @brief Gets the maximum value in the generated random number range. 01165 */ 01166 static constexpr result_type 01167 max() 01168 { return __detail::_Shift<_UIntType, __w>::__value - 1; } 01169 01170 /** 01171 * @brief Discard a sequence of random numbers. 01172 */ 01173 void 01174 discard(unsigned long long __z) 01175 { 01176 for (; __z != 0ULL; --__z) 01177 (*this)(); 01178 } 01179 01180 /** 01181 * @brief Gets the next value in the generated random number sequence. 01182 */ 01183 result_type 01184 operator()(); 01185 01186 /** 01187 * @brief Compares two %independent_bits_engine random number generator 01188 * objects of the same type for equality. 01189 * 01190 * @param __lhs A %independent_bits_engine random number generator 01191 * object. 01192 * @param __rhs Another %independent_bits_engine random number generator 01193 * object. 01194 * 01195 * @returns true if the infinite sequences of generated values 01196 * would be equal, false otherwise. 01197 */ 01198 friend bool 01199 operator==(const independent_bits_engine& __lhs, 01200 const independent_bits_engine& __rhs) 01201 { return __lhs._M_b == __rhs._M_b; } 01202 01203 /** 01204 * @brief Extracts the current state of a % subtract_with_carry_engine 01205 * random number generator engine @p __x from the input stream 01206 * @p __is. 01207 * 01208 * @param __is An input stream. 01209 * @param __x A %independent_bits_engine random number generator 01210 * engine. 01211 * 01212 * @returns The input stream with the state of @p __x extracted or in 01213 * an error state. 01214 */ 01215 template<typename _CharT, typename _Traits> 01216 friend std::basic_istream<_CharT, _Traits>& 01217 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01218 std::independent_bits_engine<_RandomNumberEngine, 01219 __w, _UIntType>& __x) 01220 { 01221 __is >> __x._M_b; 01222 return __is; 01223 } 01224 01225 private: 01226 _RandomNumberEngine _M_b; 01227 }; 01228 01229 /** 01230 * @brief Compares two %independent_bits_engine random number generator 01231 * objects of the same type for inequality. 01232 * 01233 * @param __lhs A %independent_bits_engine random number generator 01234 * object. 01235 * @param __rhs Another %independent_bits_engine random number generator 01236 * object. 01237 * 01238 * @returns true if the infinite sequences of generated values 01239 * would be different, false otherwise. 01240 */ 01241 template<typename _RandomNumberEngine, size_t __w, typename _UIntType> 01242 inline bool 01243 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w, 01244 _UIntType>& __lhs, 01245 const std::independent_bits_engine<_RandomNumberEngine, __w, 01246 _UIntType>& __rhs) 01247 { return !(__lhs == __rhs); } 01248 01249 /** 01250 * @brief Inserts the current state of a %independent_bits_engine random 01251 * number generator engine @p __x into the output stream @p __os. 01252 * 01253 * @param __os An output stream. 01254 * @param __x A %independent_bits_engine random number generator engine. 01255 * 01256 * @returns The output stream with the state of @p __x inserted or in 01257 * an error state. 01258 */ 01259 template<typename _RandomNumberEngine, size_t __w, typename _UIntType, 01260 typename _CharT, typename _Traits> 01261 std::basic_ostream<_CharT, _Traits>& 01262 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01263 const std::independent_bits_engine<_RandomNumberEngine, 01264 __w, _UIntType>& __x) 01265 { 01266 __os << __x.base(); 01267 return __os; 01268 } 01269 01270 01271 /** 01272 * @brief Produces random numbers by combining random numbers from some 01273 * base engine to produce random numbers with a specifies number of bits 01274 * @p __k. 01275 */ 01276 template<typename _RandomNumberEngine, size_t __k> 01277 class shuffle_order_engine 01278 { 01279 static_assert(1u <= __k, "template argument substituting " 01280 "__k out of bound"); 01281 01282 public: 01283 /** The type of the generated random value. */ 01284 typedef typename _RandomNumberEngine::result_type result_type; 01285 01286 static constexpr size_t table_size = __k; 01287 01288 /** 01289 * @brief Constructs a default %shuffle_order_engine engine. 01290 * 01291 * The underlying engine is default constructed as well. 01292 */ 01293 shuffle_order_engine() 01294 : _M_b() 01295 { _M_initialize(); } 01296 01297 /** 01298 * @brief Copy constructs a %shuffle_order_engine engine. 01299 * 01300 * Copies an existing base class random number generator. 01301 * @param __rng An existing (base class) engine object. 01302 */ 01303 explicit 01304 shuffle_order_engine(const _RandomNumberEngine& __rng) 01305 : _M_b(__rng) 01306 { _M_initialize(); } 01307 01308 /** 01309 * @brief Move constructs a %shuffle_order_engine engine. 01310 * 01311 * Copies an existing base class random number generator. 01312 * @param __rng An existing (base class) engine object. 01313 */ 01314 explicit 01315 shuffle_order_engine(_RandomNumberEngine&& __rng) 01316 : _M_b(std::move(__rng)) 01317 { _M_initialize(); } 01318 01319 /** 01320 * @brief Seed constructs a %shuffle_order_engine engine. 01321 * 01322 * Constructs the underlying generator engine seeded with @p __s. 01323 * @param __s A seed value for the base class engine. 01324 */ 01325 explicit 01326 shuffle_order_engine(result_type __s) 01327 : _M_b(__s) 01328 { _M_initialize(); } 01329 01330 /** 01331 * @brief Generator construct a %shuffle_order_engine engine. 01332 * 01333 * @param __q A seed sequence. 01334 */ 01335 template<typename _Sseq, typename = typename 01336 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value 01337 && !std::is_same<_Sseq, _RandomNumberEngine>::value> 01338 ::type> 01339 explicit 01340 shuffle_order_engine(_Sseq& __q) 01341 : _M_b(__q) 01342 { _M_initialize(); } 01343 01344 /** 01345 * @brief Reseeds the %shuffle_order_engine object with the default seed 01346 for the underlying base class generator engine. 01347 */ 01348 void 01349 seed() 01350 { 01351 _M_b.seed(); 01352 _M_initialize(); 01353 } 01354 01355 /** 01356 * @brief Reseeds the %shuffle_order_engine object with the default seed 01357 * for the underlying base class generator engine. 01358 */ 01359 void 01360 seed(result_type __s) 01361 { 01362 _M_b.seed(__s); 01363 _M_initialize(); 01364 } 01365 01366 /** 01367 * @brief Reseeds the %shuffle_order_engine object with the given seed 01368 * sequence. 01369 * @param __q A seed generator function. 01370 */ 01371 template<typename _Sseq> 01372 void 01373 seed(_Sseq& __q) 01374 { 01375 _M_b.seed(__q); 01376 _M_initialize(); 01377 } 01378 01379 /** 01380 * Gets a const reference to the underlying generator engine object. 01381 */ 01382 const _RandomNumberEngine& 01383 base() const noexcept 01384 { return _M_b; } 01385 01386 /** 01387 * Gets the minimum value in the generated random number range. 01388 */ 01389 static constexpr result_type 01390 min() 01391 { return _RandomNumberEngine::min(); } 01392 01393 /** 01394 * Gets the maximum value in the generated random number range. 01395 */ 01396 static constexpr result_type 01397 max() 01398 { return _RandomNumberEngine::max(); } 01399 01400 /** 01401 * Discard a sequence of random numbers. 01402 */ 01403 void 01404 discard(unsigned long long __z) 01405 { 01406 for (; __z != 0ULL; --__z) 01407 (*this)(); 01408 } 01409 01410 /** 01411 * Gets the next value in the generated random number sequence. 01412 */ 01413 result_type 01414 operator()(); 01415 01416 /** 01417 * Compares two %shuffle_order_engine random number generator objects 01418 * of the same type for equality. 01419 * 01420 * @param __lhs A %shuffle_order_engine random number generator object. 01421 * @param __rhs Another %shuffle_order_engine random number generator 01422 * object. 01423 * 01424 * @returns true if the infinite sequences of generated values 01425 * would be equal, false otherwise. 01426 */ 01427 friend bool 01428 operator==(const shuffle_order_engine& __lhs, 01429 const shuffle_order_engine& __rhs) 01430 { return (__lhs._M_b == __rhs._M_b 01431 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v) 01432 && __lhs._M_y == __rhs._M_y); } 01433 01434 /** 01435 * @brief Inserts the current state of a %shuffle_order_engine random 01436 * number generator engine @p __x into the output stream 01437 @p __os. 01438 * 01439 * @param __os An output stream. 01440 * @param __x A %shuffle_order_engine random number generator engine. 01441 * 01442 * @returns The output stream with the state of @p __x inserted or in 01443 * an error state. 01444 */ 01445 template<typename _RandomNumberEngine1, size_t __k1, 01446 typename _CharT, typename _Traits> 01447 friend std::basic_ostream<_CharT, _Traits>& 01448 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01449 const std::shuffle_order_engine<_RandomNumberEngine1, 01450 __k1>& __x); 01451 01452 /** 01453 * @brief Extracts the current state of a % subtract_with_carry_engine 01454 * random number generator engine @p __x from the input stream 01455 * @p __is. 01456 * 01457 * @param __is An input stream. 01458 * @param __x A %shuffle_order_engine random number generator engine. 01459 * 01460 * @returns The input stream with the state of @p __x extracted or in 01461 * an error state. 01462 */ 01463 template<typename _RandomNumberEngine1, size_t __k1, 01464 typename _CharT, typename _Traits> 01465 friend std::basic_istream<_CharT, _Traits>& 01466 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01467 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x); 01468 01469 private: 01470 void _M_initialize() 01471 { 01472 for (size_t __i = 0; __i < __k; ++__i) 01473 _M_v[__i] = _M_b(); 01474 _M_y = _M_b(); 01475 } 01476 01477 _RandomNumberEngine _M_b; 01478 result_type _M_v[__k]; 01479 result_type _M_y; 01480 }; 01481 01482 /** 01483 * Compares two %shuffle_order_engine random number generator objects 01484 * of the same type for inequality. 01485 * 01486 * @param __lhs A %shuffle_order_engine random number generator object. 01487 * @param __rhs Another %shuffle_order_engine random number generator 01488 * object. 01489 * 01490 * @returns true if the infinite sequences of generated values 01491 * would be different, false otherwise. 01492 */ 01493 template<typename _RandomNumberEngine, size_t __k> 01494 inline bool 01495 operator!=(const std::shuffle_order_engine<_RandomNumberEngine, 01496 __k>& __lhs, 01497 const std::shuffle_order_engine<_RandomNumberEngine, 01498 __k>& __rhs) 01499 { return !(__lhs == __rhs); } 01500 01501 01502 /** 01503 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. 01504 */ 01505 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL> 01506 minstd_rand0; 01507 01508 /** 01509 * An alternative LCR (Lehmer Generator function). 01510 */ 01511 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL> 01512 minstd_rand; 01513 01514 /** 01515 * The classic Mersenne Twister. 01516 * 01517 * Reference: 01518 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally 01519 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions 01520 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. 01521 */ 01522 typedef mersenne_twister_engine< 01523 uint_fast32_t, 01524 32, 624, 397, 31, 01525 0x9908b0dfUL, 11, 01526 0xffffffffUL, 7, 01527 0x9d2c5680UL, 15, 01528 0xefc60000UL, 18, 1812433253UL> mt19937; 01529 01530 /** 01531 * An alternative Mersenne Twister. 01532 */ 01533 typedef mersenne_twister_engine< 01534 uint_fast64_t, 01535 64, 312, 156, 31, 01536 0xb5026f5aa96619e9ULL, 29, 01537 0x5555555555555555ULL, 17, 01538 0x71d67fffeda60000ULL, 37, 01539 0xfff7eee000000000ULL, 43, 01540 6364136223846793005ULL> mt19937_64; 01541 01542 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> 01543 ranlux24_base; 01544 01545 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> 01546 ranlux48_base; 01547 01548 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 01549 01550 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 01551 01552 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 01553 01554 typedef minstd_rand0 default_random_engine; 01555 01556 /** 01557 * A standard interface to a platform-specific non-deterministic 01558 * random number generator (if any are available). 01559 */ 01560 class random_device 01561 { 01562 public: 01563 /** The type of the generated random value. */ 01564 typedef unsigned int result_type; 01565 01566 // constructors, destructors and member functions 01567 01568 #ifdef _GLIBCXX_USE_RANDOM_TR1 01569 01570 explicit 01571 random_device(const std::string& __token = "default") 01572 { 01573 _M_init(__token); 01574 } 01575 01576 ~random_device() 01577 { _M_fini(); } 01578 01579 #else 01580 01581 explicit 01582 random_device(const std::string& __token = "mt19937") 01583 { _M_init_pretr1(__token); } 01584 01585 public: 01586 01587 #endif 01588 01589 static constexpr result_type 01590 min() 01591 { return std::numeric_limits<result_type>::min(); } 01592 01593 static constexpr result_type 01594 max() 01595 { return std::numeric_limits<result_type>::max(); } 01596 01597 double 01598 entropy() const noexcept 01599 { 01600 #ifdef _GLIBCXX_USE_RANDOM_TR1 01601 return this->_M_getentropy(); 01602 #else 01603 return 0.0; 01604 #endif 01605 } 01606 01607 result_type 01608 operator()() 01609 { 01610 #ifdef _GLIBCXX_USE_RANDOM_TR1 01611 return this->_M_getval(); 01612 #else 01613 return this->_M_getval_pretr1(); 01614 #endif 01615 } 01616 01617 // No copy functions. 01618 random_device(const random_device&) = delete; 01619 void operator=(const random_device&) = delete; 01620 01621 private: 01622 01623 void _M_init(const std::string& __token); 01624 void _M_init_pretr1(const std::string& __token); 01625 void _M_fini(); 01626 01627 result_type _M_getval(); 01628 result_type _M_getval_pretr1(); 01629 double _M_getentropy() const noexcept; 01630 01631 union 01632 { 01633 void* _M_file; 01634 mt19937 _M_mt; 01635 }; 01636 }; 01637 01638 /* @} */ // group random_generators 01639 01640 /** 01641 * @addtogroup random_distributions Random Number Distributions 01642 * @ingroup random 01643 * @{ 01644 */ 01645 01646 /** 01647 * @addtogroup random_distributions_uniform Uniform Distributions 01648 * @ingroup random_distributions 01649 * @{ 01650 */ 01651 01652 // std::uniform_int_distribution is defined in <bits/uniform_int_dist.h> 01653 01654 /** 01655 * @brief Return true if two uniform integer distributions have 01656 * different parameters. 01657 */ 01658 template<typename _IntType> 01659 inline bool 01660 operator!=(const std::uniform_int_distribution<_IntType>& __d1, 01661 const std::uniform_int_distribution<_IntType>& __d2) 01662 { return !(__d1 == __d2); } 01663 01664 /** 01665 * @brief Inserts a %uniform_int_distribution random number 01666 * distribution @p __x into the output stream @p os. 01667 * 01668 * @param __os An output stream. 01669 * @param __x A %uniform_int_distribution random number distribution. 01670 * 01671 * @returns The output stream with the state of @p __x inserted or in 01672 * an error state. 01673 */ 01674 template<typename _IntType, typename _CharT, typename _Traits> 01675 std::basic_ostream<_CharT, _Traits>& 01676 operator<<(std::basic_ostream<_CharT, _Traits>&, 01677 const std::uniform_int_distribution<_IntType>&); 01678 01679 /** 01680 * @brief Extracts a %uniform_int_distribution random number distribution 01681 * @p __x from the input stream @p __is. 01682 * 01683 * @param __is An input stream. 01684 * @param __x A %uniform_int_distribution random number generator engine. 01685 * 01686 * @returns The input stream with @p __x extracted or in an error state. 01687 */ 01688 template<typename _IntType, typename _CharT, typename _Traits> 01689 std::basic_istream<_CharT, _Traits>& 01690 operator>>(std::basic_istream<_CharT, _Traits>&, 01691 std::uniform_int_distribution<_IntType>&); 01692 01693 01694 /** 01695 * @brief Uniform continuous distribution for random numbers. 01696 * 01697 * A continuous random distribution on the range [min, max) with equal 01698 * probability throughout the range. The URNG should be real-valued and 01699 * deliver number in the range [0, 1). 01700 */ 01701 template<typename _RealType = double> 01702 class uniform_real_distribution 01703 { 01704 static_assert(std::is_floating_point<_RealType>::value, 01705 "result_type must be a floating point type"); 01706 01707 public: 01708 /** The type of the range of the distribution. */ 01709 typedef _RealType result_type; 01710 01711 /** Parameter type. */ 01712 struct param_type 01713 { 01714 typedef uniform_real_distribution<_RealType> distribution_type; 01715 01716 explicit 01717 param_type(_RealType __a = _RealType(0), 01718 _RealType __b = _RealType(1)) 01719 : _M_a(__a), _M_b(__b) 01720 { 01721 __glibcxx_assert(_M_a <= _M_b); 01722 } 01723 01724 result_type 01725 a() const 01726 { return _M_a; } 01727 01728 result_type 01729 b() const 01730 { return _M_b; } 01731 01732 friend bool 01733 operator==(const param_type& __p1, const param_type& __p2) 01734 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } 01735 01736 friend bool 01737 operator!=(const param_type& __p1, const param_type& __p2) 01738 { return !(__p1 == __p2); } 01739 01740 private: 01741 _RealType _M_a; 01742 _RealType _M_b; 01743 }; 01744 01745 public: 01746 /** 01747 * @brief Constructs a uniform_real_distribution object. 01748 * 01749 * @param __a [IN] The lower bound of the distribution. 01750 * @param __b [IN] The upper bound of the distribution. 01751 */ 01752 explicit 01753 uniform_real_distribution(_RealType __a = _RealType(0), 01754 _RealType __b = _RealType(1)) 01755 : _M_param(__a, __b) 01756 { } 01757 01758 explicit 01759 uniform_real_distribution(const param_type& __p) 01760 : _M_param(__p) 01761 { } 01762 01763 /** 01764 * @brief Resets the distribution state. 01765 * 01766 * Does nothing for the uniform real distribution. 01767 */ 01768 void 01769 reset() { } 01770 01771 result_type 01772 a() const 01773 { return _M_param.a(); } 01774 01775 result_type 01776 b() const 01777 { return _M_param.b(); } 01778 01779 /** 01780 * @brief Returns the parameter set of the distribution. 01781 */ 01782 param_type 01783 param() const 01784 { return _M_param; } 01785 01786 /** 01787 * @brief Sets the parameter set of the distribution. 01788 * @param __param The new parameter set of the distribution. 01789 */ 01790 void 01791 param(const param_type& __param) 01792 { _M_param = __param; } 01793 01794 /** 01795 * @brief Returns the inclusive lower bound of the distribution range. 01796 */ 01797 result_type 01798 min() const 01799 { return this->a(); } 01800 01801 /** 01802 * @brief Returns the inclusive upper bound of the distribution range. 01803 */ 01804 result_type 01805 max() const 01806 { return this->b(); } 01807 01808 /** 01809 * @brief Generating functions. 01810 */ 01811 template<typename _UniformRandomNumberGenerator> 01812 result_type 01813 operator()(_UniformRandomNumberGenerator& __urng) 01814 { return this->operator()(__urng, _M_param); } 01815 01816 template<typename _UniformRandomNumberGenerator> 01817 result_type 01818 operator()(_UniformRandomNumberGenerator& __urng, 01819 const param_type& __p) 01820 { 01821 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 01822 __aurng(__urng); 01823 return (__aurng() * (__p.b() - __p.a())) + __p.a(); 01824 } 01825 01826 template<typename _ForwardIterator, 01827 typename _UniformRandomNumberGenerator> 01828 void 01829 __generate(_ForwardIterator __f, _ForwardIterator __t, 01830 _UniformRandomNumberGenerator& __urng) 01831 { this->__generate(__f, __t, __urng, _M_param); } 01832 01833 template<typename _ForwardIterator, 01834 typename _UniformRandomNumberGenerator> 01835 void 01836 __generate(_ForwardIterator __f, _ForwardIterator __t, 01837 _UniformRandomNumberGenerator& __urng, 01838 const param_type& __p) 01839 { this->__generate_impl(__f, __t, __urng, __p); } 01840 01841 template<typename _UniformRandomNumberGenerator> 01842 void 01843 __generate(result_type* __f, result_type* __t, 01844 _UniformRandomNumberGenerator& __urng, 01845 const param_type& __p) 01846 { this->__generate_impl(__f, __t, __urng, __p); } 01847 01848 /** 01849 * @brief Return true if two uniform real distributions have 01850 * the same parameters. 01851 */ 01852 friend bool 01853 operator==(const uniform_real_distribution& __d1, 01854 const uniform_real_distribution& __d2) 01855 { return __d1._M_param == __d2._M_param; } 01856 01857 private: 01858 template<typename _ForwardIterator, 01859 typename _UniformRandomNumberGenerator> 01860 void 01861 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 01862 _UniformRandomNumberGenerator& __urng, 01863 const param_type& __p); 01864 01865 param_type _M_param; 01866 }; 01867 01868 /** 01869 * @brief Return true if two uniform real distributions have 01870 * different parameters. 01871 */ 01872 template<typename _IntType> 01873 inline bool 01874 operator!=(const std::uniform_real_distribution<_IntType>& __d1, 01875 const std::uniform_real_distribution<_IntType>& __d2) 01876 { return !(__d1 == __d2); } 01877 01878 /** 01879 * @brief Inserts a %uniform_real_distribution random number 01880 * distribution @p __x into the output stream @p __os. 01881 * 01882 * @param __os An output stream. 01883 * @param __x A %uniform_real_distribution random number distribution. 01884 * 01885 * @returns The output stream with the state of @p __x inserted or in 01886 * an error state. 01887 */ 01888 template<typename _RealType, typename _CharT, typename _Traits> 01889 std::basic_ostream<_CharT, _Traits>& 01890 operator<<(std::basic_ostream<_CharT, _Traits>&, 01891 const std::uniform_real_distribution<_RealType>&); 01892 01893 /** 01894 * @brief Extracts a %uniform_real_distribution random number distribution 01895 * @p __x from the input stream @p __is. 01896 * 01897 * @param __is An input stream. 01898 * @param __x A %uniform_real_distribution random number generator engine. 01899 * 01900 * @returns The input stream with @p __x extracted or in an error state. 01901 */ 01902 template<typename _RealType, typename _CharT, typename _Traits> 01903 std::basic_istream<_CharT, _Traits>& 01904 operator>>(std::basic_istream<_CharT, _Traits>&, 01905 std::uniform_real_distribution<_RealType>&); 01906 01907 /* @} */ // group random_distributions_uniform 01908 01909 /** 01910 * @addtogroup random_distributions_normal Normal Distributions 01911 * @ingroup random_distributions 01912 * @{ 01913 */ 01914 01915 /** 01916 * @brief A normal continuous distribution for random numbers. 01917 * 01918 * The formula for the normal probability density function is 01919 * @f[ 01920 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}} 01921 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } 01922 * @f] 01923 */ 01924 template<typename _RealType = double> 01925 class normal_distribution 01926 { 01927 static_assert(std::is_floating_point<_RealType>::value, 01928 "result_type must be a floating point type"); 01929 01930 public: 01931 /** The type of the range of the distribution. */ 01932 typedef _RealType result_type; 01933 01934 /** Parameter type. */ 01935 struct param_type 01936 { 01937 typedef normal_distribution<_RealType> distribution_type; 01938 01939 explicit 01940 param_type(_RealType __mean = _RealType(0), 01941 _RealType __stddev = _RealType(1)) 01942 : _M_mean(__mean), _M_stddev(__stddev) 01943 { 01944 __glibcxx_assert(_M_stddev > _RealType(0)); 01945 } 01946 01947 _RealType 01948 mean() const 01949 { return _M_mean; } 01950 01951 _RealType 01952 stddev() const 01953 { return _M_stddev; } 01954 01955 friend bool 01956 operator==(const param_type& __p1, const param_type& __p2) 01957 { return (__p1._M_mean == __p2._M_mean 01958 && __p1._M_stddev == __p2._M_stddev); } 01959 01960 friend bool 01961 operator!=(const param_type& __p1, const param_type& __p2) 01962 { return !(__p1 == __p2); } 01963 01964 private: 01965 _RealType _M_mean; 01966 _RealType _M_stddev; 01967 }; 01968 01969 public: 01970 /** 01971 * Constructs a normal distribution with parameters @f$mean@f$ and 01972 * standard deviation. 01973 */ 01974 explicit 01975 normal_distribution(result_type __mean = result_type(0), 01976 result_type __stddev = result_type(1)) 01977 : _M_param(__mean, __stddev), _M_saved_available(false) 01978 { } 01979 01980 explicit 01981 normal_distribution(const param_type& __p) 01982 : _M_param(__p), _M_saved_available(false) 01983 { } 01984 01985 /** 01986 * @brief Resets the distribution state. 01987 */ 01988 void 01989 reset() 01990 { _M_saved_available = false; } 01991 01992 /** 01993 * @brief Returns the mean of the distribution. 01994 */ 01995 _RealType 01996 mean() const 01997 { return _M_param.mean(); } 01998 01999 /** 02000 * @brief Returns the standard deviation of the distribution. 02001 */ 02002 _RealType 02003 stddev() const 02004 { return _M_param.stddev(); } 02005 02006 /** 02007 * @brief Returns the parameter set of the distribution. 02008 */ 02009 param_type 02010 param() const 02011 { return _M_param; } 02012 02013 /** 02014 * @brief Sets the parameter set of the distribution. 02015 * @param __param The new parameter set of the distribution. 02016 */ 02017 void 02018 param(const param_type& __param) 02019 { _M_param = __param; } 02020 02021 /** 02022 * @brief Returns the greatest lower bound value of the distribution. 02023 */ 02024 result_type 02025 min() const 02026 { return std::numeric_limits<result_type>::lowest(); } 02027 02028 /** 02029 * @brief Returns the least upper bound value of the distribution. 02030 */ 02031 result_type 02032 max() const 02033 { return std::numeric_limits<result_type>::max(); } 02034 02035 /** 02036 * @brief Generating functions. 02037 */ 02038 template<typename _UniformRandomNumberGenerator> 02039 result_type 02040 operator()(_UniformRandomNumberGenerator& __urng) 02041 { return this->operator()(__urng, _M_param); } 02042 02043 template<typename _UniformRandomNumberGenerator> 02044 result_type 02045 operator()(_UniformRandomNumberGenerator& __urng, 02046 const param_type& __p); 02047 02048 template<typename _ForwardIterator, 02049 typename _UniformRandomNumberGenerator> 02050 void 02051 __generate(_ForwardIterator __f, _ForwardIterator __t, 02052 _UniformRandomNumberGenerator& __urng) 02053 { this->__generate(__f, __t, __urng, _M_param); } 02054 02055 template<typename _ForwardIterator, 02056 typename _UniformRandomNumberGenerator> 02057 void 02058 __generate(_ForwardIterator __f, _ForwardIterator __t, 02059 _UniformRandomNumberGenerator& __urng, 02060 const param_type& __p) 02061 { this->__generate_impl(__f, __t, __urng, __p); } 02062 02063 template<typename _UniformRandomNumberGenerator> 02064 void 02065 __generate(result_type* __f, result_type* __t, 02066 _UniformRandomNumberGenerator& __urng, 02067 const param_type& __p) 02068 { this->__generate_impl(__f, __t, __urng, __p); } 02069 02070 /** 02071 * @brief Return true if two normal distributions have 02072 * the same parameters and the sequences that would 02073 * be generated are equal. 02074 */ 02075 template<typename _RealType1> 02076 friend bool 02077 operator==(const std::normal_distribution<_RealType1>& __d1, 02078 const std::normal_distribution<_RealType1>& __d2); 02079 02080 /** 02081 * @brief Inserts a %normal_distribution random number distribution 02082 * @p __x into the output stream @p __os. 02083 * 02084 * @param __os An output stream. 02085 * @param __x A %normal_distribution random number distribution. 02086 * 02087 * @returns The output stream with the state of @p __x inserted or in 02088 * an error state. 02089 */ 02090 template<typename _RealType1, typename _CharT, typename _Traits> 02091 friend std::basic_ostream<_CharT, _Traits>& 02092 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 02093 const std::normal_distribution<_RealType1>& __x); 02094 02095 /** 02096 * @brief Extracts a %normal_distribution random number distribution 02097 * @p __x from the input stream @p __is. 02098 * 02099 * @param __is An input stream. 02100 * @param __x A %normal_distribution random number generator engine. 02101 * 02102 * @returns The input stream with @p __x extracted or in an error 02103 * state. 02104 */ 02105 template<typename _RealType1, typename _CharT, typename _Traits> 02106 friend std::basic_istream<_CharT, _Traits>& 02107 operator>>(std::basic_istream<_CharT, _Traits>& __is, 02108 std::normal_distribution<_RealType1>& __x); 02109 02110 private: 02111 template<typename _ForwardIterator, 02112 typename _UniformRandomNumberGenerator> 02113 void 02114 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02115 _UniformRandomNumberGenerator& __urng, 02116 const param_type& __p); 02117 02118 param_type _M_param; 02119 result_type _M_saved; 02120 bool _M_saved_available; 02121 }; 02122 02123 /** 02124 * @brief Return true if two normal distributions are different. 02125 */ 02126 template<typename _RealType> 02127 inline bool 02128 operator!=(const std::normal_distribution<_RealType>& __d1, 02129 const std::normal_distribution<_RealType>& __d2) 02130 { return !(__d1 == __d2); } 02131 02132 02133 /** 02134 * @brief A lognormal_distribution random number distribution. 02135 * 02136 * The formula for the normal probability mass function is 02137 * @f[ 02138 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}} 02139 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} 02140 * @f] 02141 */ 02142 template<typename _RealType = double> 02143 class lognormal_distribution 02144 { 02145 static_assert(std::is_floating_point<_RealType>::value, 02146 "result_type must be a floating point type"); 02147 02148 public: 02149 /** The type of the range of the distribution. */ 02150 typedef _RealType result_type; 02151 02152 /** Parameter type. */ 02153 struct param_type 02154 { 02155 typedef lognormal_distribution<_RealType> distribution_type; 02156 02157 explicit 02158 param_type(_RealType __m = _RealType(0), 02159 _RealType __s = _RealType(1)) 02160 : _M_m(__m), _M_s(__s) 02161 { } 02162 02163 _RealType 02164 m() const 02165 { return _M_m; } 02166 02167 _RealType 02168 s() const 02169 { return _M_s; } 02170 02171 friend bool 02172 operator==(const param_type& __p1, const param_type& __p2) 02173 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; } 02174 02175 friend bool 02176 operator!=(const param_type& __p1, const param_type& __p2) 02177 { return !(__p1 == __p2); } 02178 02179 private: 02180 _RealType _M_m; 02181 _RealType _M_s; 02182 }; 02183 02184 explicit 02185 lognormal_distribution(_RealType __m = _RealType(0), 02186 _RealType __s = _RealType(1)) 02187 : _M_param(__m, __s), _M_nd() 02188 { } 02189 02190 explicit 02191 lognormal_distribution(const param_type& __p) 02192 : _M_param(__p), _M_nd() 02193 { } 02194 02195 /** 02196 * Resets the distribution state. 02197 */ 02198 void 02199 reset() 02200 { _M_nd.reset(); } 02201 02202 /** 02203 * 02204 */ 02205 _RealType 02206 m() const 02207 { return _M_param.m(); } 02208 02209 _RealType 02210 s() const 02211 { return _M_param.s(); } 02212 02213 /** 02214 * @brief Returns the parameter set of the distribution. 02215 */ 02216 param_type 02217 param() const 02218 { return _M_param; } 02219 02220 /** 02221 * @brief Sets the parameter set of the distribution. 02222 * @param __param The new parameter set of the distribution. 02223 */ 02224 void 02225 param(const param_type& __param) 02226 { _M_param = __param; } 02227 02228 /** 02229 * @brief Returns the greatest lower bound value of the distribution. 02230 */ 02231 result_type 02232 min() const 02233 { return result_type(0); } 02234 02235 /** 02236 * @brief Returns the least upper bound value of the distribution. 02237 */ 02238 result_type 02239 max() const 02240 { return std::numeric_limits<result_type>::max(); } 02241 02242 /** 02243 * @brief Generating functions. 02244 */ 02245 template<typename _UniformRandomNumberGenerator> 02246 result_type 02247 operator()(_UniformRandomNumberGenerator& __urng) 02248 { return this->operator()(__urng, _M_param); } 02249 02250 template<typename _UniformRandomNumberGenerator> 02251 result_type 02252 operator()(_UniformRandomNumberGenerator& __urng, 02253 const param_type& __p) 02254 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); } 02255 02256 template<typename _ForwardIterator, 02257 typename _UniformRandomNumberGenerator> 02258 void 02259 __generate(_ForwardIterator __f, _ForwardIterator __t, 02260 _UniformRandomNumberGenerator& __urng) 02261 { this->__generate(__f, __t, __urng, _M_param); } 02262 02263 template<typename _ForwardIterator, 02264 typename _UniformRandomNumberGenerator> 02265 void 02266 __generate(_ForwardIterator __f, _ForwardIterator __t, 02267 _UniformRandomNumberGenerator& __urng, 02268 const param_type& __p) 02269 { this->__generate_impl(__f, __t, __urng, __p); } 02270 02271 template<typename _UniformRandomNumberGenerator> 02272 void 02273 __generate(result_type* __f, result_type* __t, 02274 _UniformRandomNumberGenerator& __urng, 02275 const param_type& __p) 02276 { this->__generate_impl(__f, __t, __urng, __p); } 02277 02278 /** 02279 * @brief Return true if two lognormal distributions have 02280 * the same parameters and the sequences that would 02281 * be generated are equal. 02282 */ 02283 friend bool 02284 operator==(const lognormal_distribution& __d1, 02285 const lognormal_distribution& __d2) 02286 { return (__d1._M_param == __d2._M_param 02287 && __d1._M_nd == __d2._M_nd); } 02288 02289 /** 02290 * @brief Inserts a %lognormal_distribution random number distribution 02291 * @p __x into the output stream @p __os. 02292 * 02293 * @param __os An output stream. 02294 * @param __x A %lognormal_distribution random number distribution. 02295 * 02296 * @returns The output stream with the state of @p __x inserted or in 02297 * an error state. 02298 */ 02299 template<typename _RealType1, typename _CharT, typename _Traits> 02300 friend std::basic_ostream<_CharT, _Traits>& 02301 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 02302 const std::lognormal_distribution<_RealType1>& __x); 02303 02304 /** 02305 * @brief Extracts a %lognormal_distribution random number distribution 02306 * @p __x from the input stream @p __is. 02307 * 02308 * @param __is An input stream. 02309 * @param __x A %lognormal_distribution random number 02310 * generator engine. 02311 * 02312 * @returns The input stream with @p __x extracted or in an error state. 02313 */ 02314 template<typename _RealType1, typename _CharT, typename _Traits> 02315 friend std::basic_istream<_CharT, _Traits>& 02316 operator>>(std::basic_istream<_CharT, _Traits>& __is, 02317 std::lognormal_distribution<_RealType1>& __x); 02318 02319 private: 02320 template<typename _ForwardIterator, 02321 typename _UniformRandomNumberGenerator> 02322 void 02323 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02324 _UniformRandomNumberGenerator& __urng, 02325 const param_type& __p); 02326 02327 param_type _M_param; 02328 02329 std::normal_distribution<result_type> _M_nd; 02330 }; 02331 02332 /** 02333 * @brief Return true if two lognormal distributions are different. 02334 */ 02335 template<typename _RealType> 02336 inline bool 02337 operator!=(const std::lognormal_distribution<_RealType>& __d1, 02338 const std::lognormal_distribution<_RealType>& __d2) 02339 { return !(__d1 == __d2); } 02340 02341 02342 /** 02343 * @brief A gamma continuous distribution for random numbers. 02344 * 02345 * The formula for the gamma probability density function is: 02346 * @f[ 02347 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)} 02348 * (x/\beta)^{\alpha - 1} e^{-x/\beta} 02349 * @f] 02350 */ 02351 template<typename _RealType = double> 02352 class gamma_distribution 02353 { 02354 static_assert(std::is_floating_point<_RealType>::value, 02355 "result_type must be a floating point type"); 02356 02357 public: 02358 /** The type of the range of the distribution. */ 02359 typedef _RealType result_type; 02360 02361 /** Parameter type. */ 02362 struct param_type 02363 { 02364 typedef gamma_distribution<_RealType> distribution_type; 02365 friend class gamma_distribution<_RealType>; 02366 02367 explicit 02368 param_type(_RealType __alpha_val = _RealType(1), 02369 _RealType __beta_val = _RealType(1)) 02370 : _M_alpha(__alpha_val), _M_beta(__beta_val) 02371 { 02372 __glibcxx_assert(_M_alpha > _RealType(0)); 02373 _M_initialize(); 02374 } 02375 02376 _RealType 02377 alpha() const 02378 { return _M_alpha; } 02379 02380 _RealType 02381 beta() const 02382 { return _M_beta; } 02383 02384 friend bool 02385 operator==(const param_type& __p1, const param_type& __p2) 02386 { return (__p1._M_alpha == __p2._M_alpha 02387 && __p1._M_beta == __p2._M_beta); } 02388 02389 friend bool 02390 operator!=(const param_type& __p1, const param_type& __p2) 02391 { return !(__p1 == __p2); } 02392 02393 private: 02394 void 02395 _M_initialize(); 02396 02397 _RealType _M_alpha; 02398 _RealType _M_beta; 02399 02400 _RealType _M_malpha, _M_a2; 02401 }; 02402 02403 public: 02404 /** 02405 * @brief Constructs a gamma distribution with parameters 02406 * @f$\alpha@f$ and @f$\beta@f$. 02407 */ 02408 explicit 02409 gamma_distribution(_RealType __alpha_val = _RealType(1), 02410 _RealType __beta_val = _RealType(1)) 02411 : _M_param(__alpha_val, __beta_val), _M_nd() 02412 { } 02413 02414 explicit 02415 gamma_distribution(const param_type& __p) 02416 : _M_param(__p), _M_nd() 02417 { } 02418 02419 /** 02420 * @brief Resets the distribution state. 02421 */ 02422 void 02423 reset() 02424 { _M_nd.reset(); } 02425 02426 /** 02427 * @brief Returns the @f$\alpha@f$ of the distribution. 02428 */ 02429 _RealType 02430 alpha() const 02431 { return _M_param.alpha(); } 02432 02433 /** 02434 * @brief Returns the @f$\beta@f$ of the distribution. 02435 */ 02436 _RealType 02437 beta() const 02438 { return _M_param.beta(); } 02439 02440 /** 02441 * @brief Returns the parameter set of the distribution. 02442 */ 02443 param_type 02444 param() const 02445 { return _M_param; } 02446 02447 /** 02448 * @brief Sets the parameter set of the distribution. 02449 * @param __param The new parameter set of the distribution. 02450 */ 02451 void 02452 param(const param_type& __param) 02453 { _M_param = __param; } 02454 02455 /** 02456 * @brief Returns the greatest lower bound value of the distribution. 02457 */ 02458 result_type 02459 min() const 02460 { return result_type(0); } 02461 02462 /** 02463 * @brief Returns the least upper bound value of the distribution. 02464 */ 02465 result_type 02466 max() const 02467 { return std::numeric_limits<result_type>::max(); } 02468 02469 /** 02470 * @brief Generating functions. 02471 */ 02472 template<typename _UniformRandomNumberGenerator> 02473 result_type 02474 operator()(_UniformRandomNumberGenerator& __urng) 02475 { return this->operator()(__urng, _M_param); } 02476 02477 template<typename _UniformRandomNumberGenerator> 02478 result_type 02479 operator()(_UniformRandomNumberGenerator& __urng, 02480 const param_type& __p); 02481 02482 template<typename _ForwardIterator, 02483 typename _UniformRandomNumberGenerator> 02484 void 02485 __generate(_ForwardIterator __f, _ForwardIterator __t, 02486 _UniformRandomNumberGenerator& __urng) 02487 { this->__generate(__f, __t, __urng, _M_param); } 02488 02489 template<typename _ForwardIterator, 02490 typename _UniformRandomNumberGenerator> 02491 void 02492 __generate(_ForwardIterator __f, _ForwardIterator __t, 02493 _UniformRandomNumberGenerator& __urng, 02494 const param_type& __p) 02495 { this->__generate_impl(__f, __t, __urng, __p); } 02496 02497 template<typename _UniformRandomNumberGenerator> 02498 void 02499 __generate(result_type* __f, result_type* __t, 02500 _UniformRandomNumberGenerator& __urng, 02501 const param_type& __p) 02502 { this->__generate_impl(__f, __t, __urng, __p); } 02503 02504 /** 02505 * @brief Return true if two gamma distributions have the same 02506 * parameters and the sequences that would be generated 02507 * are equal. 02508 */ 02509 friend bool 02510 operator==(const gamma_distribution& __d1, 02511 const gamma_distribution& __d2) 02512 { return (__d1._M_param == __d2._M_param 02513 && __d1._M_nd == __d2._M_nd); } 02514 02515 /** 02516 * @brief Inserts a %gamma_distribution random number distribution 02517 * @p __x into the output stream @p __os. 02518 * 02519 * @param __os An output stream. 02520 * @param __x A %gamma_distribution random number distribution. 02521 * 02522 * @returns The output stream with the state of @p __x inserted or in 02523 * an error state. 02524 */ 02525 template<typename _RealType1, typename _CharT, typename _Traits> 02526 friend std::basic_ostream<_CharT, _Traits>& 02527 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 02528 const std::gamma_distribution<_RealType1>& __x); 02529 02530 /** 02531 * @brief Extracts a %gamma_distribution random number distribution 02532 * @p __x from the input stream @p __is. 02533 * 02534 * @param __is An input stream. 02535 * @param __x A %gamma_distribution random number generator engine. 02536 * 02537 * @returns The input stream with @p __x extracted or in an error state. 02538 */ 02539 template<typename _RealType1, typename _CharT, typename _Traits> 02540 friend std::basic_istream<_CharT, _Traits>& 02541 operator>>(std::basic_istream<_CharT, _Traits>& __is, 02542 std::gamma_distribution<_RealType1>& __x); 02543 02544 private: 02545 template<typename _ForwardIterator, 02546 typename _UniformRandomNumberGenerator> 02547 void 02548 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02549 _UniformRandomNumberGenerator& __urng, 02550 const param_type& __p); 02551 02552 param_type _M_param; 02553 02554 std::normal_distribution<result_type> _M_nd; 02555 }; 02556 02557 /** 02558 * @brief Return true if two gamma distributions are different. 02559 */ 02560 template<typename _RealType> 02561 inline bool 02562 operator!=(const std::gamma_distribution<_RealType>& __d1, 02563 const std::gamma_distribution<_RealType>& __d2) 02564 { return !(__d1 == __d2); } 02565 02566 02567 /** 02568 * @brief A chi_squared_distribution random number distribution. 02569 * 02570 * The formula for the normal probability mass function is 02571 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$ 02572 */ 02573 template<typename _RealType = double> 02574 class chi_squared_distribution 02575 { 02576 static_assert(std::is_floating_point<_RealType>::value, 02577 "result_type must be a floating point type"); 02578 02579 public: 02580 /** The type of the range of the distribution. */ 02581 typedef _RealType result_type; 02582 02583 /** Parameter type. */ 02584 struct param_type 02585 { 02586 typedef chi_squared_distribution<_RealType> distribution_type; 02587 02588 explicit 02589 param_type(_RealType __n = _RealType(1)) 02590 : _M_n(__n) 02591 { } 02592 02593 _RealType 02594 n() const 02595 { return _M_n; } 02596 02597 friend bool 02598 operator==(const param_type& __p1, const param_type& __p2) 02599 { return __p1._M_n == __p2._M_n; } 02600 02601 friend bool 02602 operator!=(const param_type& __p1, const param_type& __p2) 02603 { return !(__p1 == __p2); } 02604 02605 private: 02606 _RealType _M_n; 02607 }; 02608 02609 explicit 02610 chi_squared_distribution(_RealType __n = _RealType(1)) 02611 : _M_param(__n), _M_gd(__n / 2) 02612 { } 02613 02614 explicit 02615 chi_squared_distribution(const param_type& __p) 02616 : _M_param(__p), _M_gd(__p.n() / 2) 02617 { } 02618 02619 /** 02620 * @brief Resets the distribution state. 02621 */ 02622 void 02623 reset() 02624 { _M_gd.reset(); } 02625 02626 /** 02627 * 02628 */ 02629 _RealType 02630 n() const 02631 { return _M_param.n(); } 02632 02633 /** 02634 * @brief Returns the parameter set of the distribution. 02635 */ 02636 param_type 02637 param() const 02638 { return _M_param; } 02639 02640 /** 02641 * @brief Sets the parameter set of the distribution. 02642 * @param __param The new parameter set of the distribution. 02643 */ 02644 void 02645 param(const param_type& __param) 02646 { 02647 _M_param = __param; 02648 typedef typename std::gamma_distribution<result_type>::param_type 02649 param_type; 02650 _M_gd.param(param_type{__param.n() / 2}); 02651 } 02652 02653 /** 02654 * @brief Returns the greatest lower bound value of the distribution. 02655 */ 02656 result_type 02657 min() const 02658 { return result_type(0); } 02659 02660 /** 02661 * @brief Returns the least upper bound value of the distribution. 02662 */ 02663 result_type 02664 max() const 02665 { return std::numeric_limits<result_type>::max(); } 02666 02667 /** 02668 * @brief Generating functions. 02669 */ 02670 template<typename _UniformRandomNumberGenerator> 02671 result_type 02672 operator()(_UniformRandomNumberGenerator& __urng) 02673 { return 2 * _M_gd(__urng); } 02674 02675 template<typename _UniformRandomNumberGenerator> 02676 result_type 02677 operator()(_UniformRandomNumberGenerator& __urng, 02678 const param_type& __p) 02679 { 02680 typedef typename std::gamma_distribution<result_type>::param_type 02681 param_type; 02682 return 2 * _M_gd(__urng, param_type(__p.n() / 2)); 02683 } 02684 02685 template<typename _ForwardIterator, 02686 typename _UniformRandomNumberGenerator> 02687 void 02688 __generate(_ForwardIterator __f, _ForwardIterator __t, 02689 _UniformRandomNumberGenerator& __urng) 02690 { this->__generate_impl(__f, __t, __urng); } 02691 02692 template<typename _ForwardIterator, 02693 typename _UniformRandomNumberGenerator> 02694 void 02695 __generate(_ForwardIterator __f, _ForwardIterator __t, 02696 _UniformRandomNumberGenerator& __urng, 02697 const param_type& __p) 02698 { typename std::gamma_distribution<result_type>::param_type 02699 __p2(__p.n() / 2); 02700 this->__generate_impl(__f, __t, __urng, __p2); } 02701 02702 template<typename _UniformRandomNumberGenerator> 02703 void 02704 __generate(result_type* __f, result_type* __t, 02705 _UniformRandomNumberGenerator& __urng) 02706 { this->__generate_impl(__f, __t, __urng); } 02707 02708 template<typename _UniformRandomNumberGenerator> 02709 void 02710 __generate(result_type* __f, result_type* __t, 02711 _UniformRandomNumberGenerator& __urng, 02712 const param_type& __p) 02713 { typename std::gamma_distribution<result_type>::param_type 02714 __p2(__p.n() / 2); 02715 this->__generate_impl(__f, __t, __urng, __p2); } 02716 02717 /** 02718 * @brief Return true if two Chi-squared distributions have 02719 * the same parameters and the sequences that would be 02720 * generated are equal. 02721 */ 02722 friend bool 02723 operator==(const chi_squared_distribution& __d1, 02724 const chi_squared_distribution& __d2) 02725 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; } 02726 02727 /** 02728 * @brief Inserts a %chi_squared_distribution random number distribution 02729 * @p __x into the output stream @p __os. 02730 * 02731 * @param __os An output stream. 02732 * @param __x A %chi_squared_distribution random number distribution. 02733 * 02734 * @returns The output stream with the state of @p __x inserted or in 02735 * an error state. 02736 */ 02737 template<typename _RealType1, typename _CharT, typename _Traits> 02738 friend std::basic_ostream<_CharT, _Traits>& 02739 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 02740 const std::chi_squared_distribution<_RealType1>& __x); 02741 02742 /** 02743 * @brief Extracts a %chi_squared_distribution random number distribution 02744 * @p __x from the input stream @p __is. 02745 * 02746 * @param __is An input stream. 02747 * @param __x A %chi_squared_distribution random number 02748 * generator engine. 02749 * 02750 * @returns The input stream with @p __x extracted or in an error state. 02751 */ 02752 template<typename _RealType1, typename _CharT, typename _Traits> 02753 friend std::basic_istream<_CharT, _Traits>& 02754 operator>>(std::basic_istream<_CharT, _Traits>& __is, 02755 std::chi_squared_distribution<_RealType1>& __x); 02756 02757 private: 02758 template<typename _ForwardIterator, 02759 typename _UniformRandomNumberGenerator> 02760 void 02761 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02762 _UniformRandomNumberGenerator& __urng); 02763 02764 template<typename _ForwardIterator, 02765 typename _UniformRandomNumberGenerator> 02766 void 02767 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02768 _UniformRandomNumberGenerator& __urng, 02769 const typename 02770 std::gamma_distribution<result_type>::param_type& __p); 02771 02772 param_type _M_param; 02773 02774 std::gamma_distribution<result_type> _M_gd; 02775 }; 02776 02777 /** 02778 * @brief Return true if two Chi-squared distributions are different. 02779 */ 02780 template<typename _RealType> 02781 inline bool 02782 operator!=(const std::chi_squared_distribution<_RealType>& __d1, 02783 const std::chi_squared_distribution<_RealType>& __d2) 02784 { return !(__d1 == __d2); } 02785 02786 02787 /** 02788 * @brief A cauchy_distribution random number distribution. 02789 * 02790 * The formula for the normal probability mass function is 02791 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$ 02792 */ 02793 template<typename _RealType = double> 02794 class cauchy_distribution 02795 { 02796 static_assert(std::is_floating_point<_RealType>::value, 02797 "result_type must be a floating point type"); 02798 02799 public: 02800 /** The type of the range of the distribution. */ 02801 typedef _RealType result_type; 02802 02803 /** Parameter type. */ 02804 struct param_type 02805 { 02806 typedef cauchy_distribution<_RealType> distribution_type; 02807 02808 explicit 02809 param_type(_RealType __a = _RealType(0), 02810 _RealType __b = _RealType(1)) 02811 : _M_a(__a), _M_b(__b) 02812 { } 02813 02814 _RealType 02815 a() const 02816 { return _M_a; } 02817 02818 _RealType 02819 b() const 02820 { return _M_b; } 02821 02822 friend bool 02823 operator==(const param_type& __p1, const param_type& __p2) 02824 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } 02825 02826 friend bool 02827 operator!=(const param_type& __p1, const param_type& __p2) 02828 { return !(__p1 == __p2); } 02829 02830 private: 02831 _RealType _M_a; 02832 _RealType _M_b; 02833 }; 02834 02835 explicit 02836 cauchy_distribution(_RealType __a = _RealType(0), 02837 _RealType __b = _RealType(1)) 02838 : _M_param(__a, __b) 02839 { } 02840 02841 explicit 02842 cauchy_distribution(const param_type& __p) 02843 : _M_param(__p) 02844 { } 02845 02846 /** 02847 * @brief Resets the distribution state. 02848 */ 02849 void 02850 reset() 02851 { } 02852 02853 /** 02854 * 02855 */ 02856 _RealType 02857 a() const 02858 { return _M_param.a(); } 02859 02860 _RealType 02861 b() const 02862 { return _M_param.b(); } 02863 02864 /** 02865 * @brief Returns the parameter set of the distribution. 02866 */ 02867 param_type 02868 param() const 02869 { return _M_param; } 02870 02871 /** 02872 * @brief Sets the parameter set of the distribution. 02873 * @param __param The new parameter set of the distribution. 02874 */ 02875 void 02876 param(const param_type& __param) 02877 { _M_param = __param; } 02878 02879 /** 02880 * @brief Returns the greatest lower bound value of the distribution. 02881 */ 02882 result_type 02883 min() const 02884 { return std::numeric_limits<result_type>::lowest(); } 02885 02886 /** 02887 * @brief Returns the least upper bound value of the distribution. 02888 */ 02889 result_type 02890 max() const 02891 { return std::numeric_limits<result_type>::max(); } 02892 02893 /** 02894 * @brief Generating functions. 02895 */ 02896 template<typename _UniformRandomNumberGenerator> 02897 result_type 02898 operator()(_UniformRandomNumberGenerator& __urng) 02899 { return this->operator()(__urng, _M_param); } 02900 02901 template<typename _UniformRandomNumberGenerator> 02902 result_type 02903 operator()(_UniformRandomNumberGenerator& __urng, 02904 const param_type& __p); 02905 02906 template<typename _ForwardIterator, 02907 typename _UniformRandomNumberGenerator> 02908 void 02909 __generate(_ForwardIterator __f, _ForwardIterator __t, 02910 _UniformRandomNumberGenerator& __urng) 02911 { this->__generate(__f, __t, __urng, _M_param); } 02912 02913 template<typename _ForwardIterator, 02914 typename _UniformRandomNumberGenerator> 02915 void 02916 __generate(_ForwardIterator __f, _ForwardIterator __t, 02917 _UniformRandomNumberGenerator& __urng, 02918 const param_type& __p) 02919 { this->__generate_impl(__f, __t, __urng, __p); } 02920 02921 template<typename _UniformRandomNumberGenerator> 02922 void 02923 __generate(result_type* __f, result_type* __t, 02924 _UniformRandomNumberGenerator& __urng, 02925 const param_type& __p) 02926 { this->__generate_impl(__f, __t, __urng, __p); } 02927 02928 /** 02929 * @brief Return true if two Cauchy distributions have 02930 * the same parameters. 02931 */ 02932 friend bool 02933 operator==(const cauchy_distribution& __d1, 02934 const cauchy_distribution& __d2) 02935 { return __d1._M_param == __d2._M_param; } 02936 02937 private: 02938 template<typename _ForwardIterator, 02939 typename _UniformRandomNumberGenerator> 02940 void 02941 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 02942 _UniformRandomNumberGenerator& __urng, 02943 const param_type& __p); 02944 02945 param_type _M_param; 02946 }; 02947 02948 /** 02949 * @brief Return true if two Cauchy distributions have 02950 * different parameters. 02951 */ 02952 template<typename _RealType> 02953 inline bool 02954 operator!=(const std::cauchy_distribution<_RealType>& __d1, 02955 const std::cauchy_distribution<_RealType>& __d2) 02956 { return !(__d1 == __d2); } 02957 02958 /** 02959 * @brief Inserts a %cauchy_distribution random number distribution 02960 * @p __x into the output stream @p __os. 02961 * 02962 * @param __os An output stream. 02963 * @param __x A %cauchy_distribution random number distribution. 02964 * 02965 * @returns The output stream with the state of @p __x inserted or in 02966 * an error state. 02967 */ 02968 template<typename _RealType, typename _CharT, typename _Traits> 02969 std::basic_ostream<_CharT, _Traits>& 02970 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 02971 const std::cauchy_distribution<_RealType>& __x); 02972 02973 /** 02974 * @brief Extracts a %cauchy_distribution random number distribution 02975 * @p __x from the input stream @p __is. 02976 * 02977 * @param __is An input stream. 02978 * @param __x A %cauchy_distribution random number 02979 * generator engine. 02980 * 02981 * @returns The input stream with @p __x extracted or in an error state. 02982 */ 02983 template<typename _RealType, typename _CharT, typename _Traits> 02984 std::basic_istream<_CharT, _Traits>& 02985 operator>>(std::basic_istream<_CharT, _Traits>& __is, 02986 std::cauchy_distribution<_RealType>& __x); 02987 02988 02989 /** 02990 * @brief A fisher_f_distribution random number distribution. 02991 * 02992 * The formula for the normal probability mass function is 02993 * @f[ 02994 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)} 02995 * (\frac{m}{n})^{m/2} x^{(m/2)-1} 02996 * (1 + \frac{mx}{n})^{-(m+n)/2} 02997 * @f] 02998 */ 02999 template<typename _RealType = double> 03000 class fisher_f_distribution 03001 { 03002 static_assert(std::is_floating_point<_RealType>::value, 03003 "result_type must be a floating point type"); 03004 03005 public: 03006 /** The type of the range of the distribution. */ 03007 typedef _RealType result_type; 03008 03009 /** Parameter type. */ 03010 struct param_type 03011 { 03012 typedef fisher_f_distribution<_RealType> distribution_type; 03013 03014 explicit 03015 param_type(_RealType __m = _RealType(1), 03016 _RealType __n = _RealType(1)) 03017 : _M_m(__m), _M_n(__n) 03018 { } 03019 03020 _RealType 03021 m() const 03022 { return _M_m; } 03023 03024 _RealType 03025 n() const 03026 { return _M_n; } 03027 03028 friend bool 03029 operator==(const param_type& __p1, const param_type& __p2) 03030 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; } 03031 03032 friend bool 03033 operator!=(const param_type& __p1, const param_type& __p2) 03034 { return !(__p1 == __p2); } 03035 03036 private: 03037 _RealType _M_m; 03038 _RealType _M_n; 03039 }; 03040 03041 explicit 03042 fisher_f_distribution(_RealType __m = _RealType(1), 03043 _RealType __n = _RealType(1)) 03044 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2) 03045 { } 03046 03047 explicit 03048 fisher_f_distribution(const param_type& __p) 03049 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2) 03050 { } 03051 03052 /** 03053 * @brief Resets the distribution state. 03054 */ 03055 void 03056 reset() 03057 { 03058 _M_gd_x.reset(); 03059 _M_gd_y.reset(); 03060 } 03061 03062 /** 03063 * 03064 */ 03065 _RealType 03066 m() const 03067 { return _M_param.m(); } 03068 03069 _RealType 03070 n() const 03071 { return _M_param.n(); } 03072 03073 /** 03074 * @brief Returns the parameter set of the distribution. 03075 */ 03076 param_type 03077 param() const 03078 { return _M_param; } 03079 03080 /** 03081 * @brief Sets the parameter set of the distribution. 03082 * @param __param The new parameter set of the distribution. 03083 */ 03084 void 03085 param(const param_type& __param) 03086 { _M_param = __param; } 03087 03088 /** 03089 * @brief Returns the greatest lower bound value of the distribution. 03090 */ 03091 result_type 03092 min() const 03093 { return result_type(0); } 03094 03095 /** 03096 * @brief Returns the least upper bound value of the distribution. 03097 */ 03098 result_type 03099 max() const 03100 { return std::numeric_limits<result_type>::max(); } 03101 03102 /** 03103 * @brief Generating functions. 03104 */ 03105 template<typename _UniformRandomNumberGenerator> 03106 result_type 03107 operator()(_UniformRandomNumberGenerator& __urng) 03108 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); } 03109 03110 template<typename _UniformRandomNumberGenerator> 03111 result_type 03112 operator()(_UniformRandomNumberGenerator& __urng, 03113 const param_type& __p) 03114 { 03115 typedef typename std::gamma_distribution<result_type>::param_type 03116 param_type; 03117 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n()) 03118 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m())); 03119 } 03120 03121 template<typename _ForwardIterator, 03122 typename _UniformRandomNumberGenerator> 03123 void 03124 __generate(_ForwardIterator __f, _ForwardIterator __t, 03125 _UniformRandomNumberGenerator& __urng) 03126 { this->__generate_impl(__f, __t, __urng); } 03127 03128 template<typename _ForwardIterator, 03129 typename _UniformRandomNumberGenerator> 03130 void 03131 __generate(_ForwardIterator __f, _ForwardIterator __t, 03132 _UniformRandomNumberGenerator& __urng, 03133 const param_type& __p) 03134 { this->__generate_impl(__f, __t, __urng, __p); } 03135 03136 template<typename _UniformRandomNumberGenerator> 03137 void 03138 __generate(result_type* __f, result_type* __t, 03139 _UniformRandomNumberGenerator& __urng) 03140 { this->__generate_impl(__f, __t, __urng); } 03141 03142 template<typename _UniformRandomNumberGenerator> 03143 void 03144 __generate(result_type* __f, result_type* __t, 03145 _UniformRandomNumberGenerator& __urng, 03146 const param_type& __p) 03147 { this->__generate_impl(__f, __t, __urng, __p); } 03148 03149 /** 03150 * @brief Return true if two Fisher f distributions have 03151 * the same parameters and the sequences that would 03152 * be generated are equal. 03153 */ 03154 friend bool 03155 operator==(const fisher_f_distribution& __d1, 03156 const fisher_f_distribution& __d2) 03157 { return (__d1._M_param == __d2._M_param 03158 && __d1._M_gd_x == __d2._M_gd_x 03159 && __d1._M_gd_y == __d2._M_gd_y); } 03160 03161 /** 03162 * @brief Inserts a %fisher_f_distribution random number distribution 03163 * @p __x into the output stream @p __os. 03164 * 03165 * @param __os An output stream. 03166 * @param __x A %fisher_f_distribution random number distribution. 03167 * 03168 * @returns The output stream with the state of @p __x inserted or in 03169 * an error state. 03170 */ 03171 template<typename _RealType1, typename _CharT, typename _Traits> 03172 friend std::basic_ostream<_CharT, _Traits>& 03173 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 03174 const std::fisher_f_distribution<_RealType1>& __x); 03175 03176 /** 03177 * @brief Extracts a %fisher_f_distribution random number distribution 03178 * @p __x from the input stream @p __is. 03179 * 03180 * @param __is An input stream. 03181 * @param __x A %fisher_f_distribution random number 03182 * generator engine. 03183 * 03184 * @returns The input stream with @p __x extracted or in an error state. 03185 */ 03186 template<typename _RealType1, typename _CharT, typename _Traits> 03187 friend std::basic_istream<_CharT, _Traits>& 03188 operator>>(std::basic_istream<_CharT, _Traits>& __is, 03189 std::fisher_f_distribution<_RealType1>& __x); 03190 03191 private: 03192 template<typename _ForwardIterator, 03193 typename _UniformRandomNumberGenerator> 03194 void 03195 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03196 _UniformRandomNumberGenerator& __urng); 03197 03198 template<typename _ForwardIterator, 03199 typename _UniformRandomNumberGenerator> 03200 void 03201 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03202 _UniformRandomNumberGenerator& __urng, 03203 const param_type& __p); 03204 03205 param_type _M_param; 03206 03207 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y; 03208 }; 03209 03210 /** 03211 * @brief Return true if two Fisher f distributions are different. 03212 */ 03213 template<typename _RealType> 03214 inline bool 03215 operator!=(const std::fisher_f_distribution<_RealType>& __d1, 03216 const std::fisher_f_distribution<_RealType>& __d2) 03217 { return !(__d1 == __d2); } 03218 03219 /** 03220 * @brief A student_t_distribution random number distribution. 03221 * 03222 * The formula for the normal probability mass function is: 03223 * @f[ 03224 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)} 03225 * (1 + \frac{x^2}{n}) ^{-(n+1)/2} 03226 * @f] 03227 */ 03228 template<typename _RealType = double> 03229 class student_t_distribution 03230 { 03231 static_assert(std::is_floating_point<_RealType>::value, 03232 "result_type must be a floating point type"); 03233 03234 public: 03235 /** The type of the range of the distribution. */ 03236 typedef _RealType result_type; 03237 03238 /** Parameter type. */ 03239 struct param_type 03240 { 03241 typedef student_t_distribution<_RealType> distribution_type; 03242 03243 explicit 03244 param_type(_RealType __n = _RealType(1)) 03245 : _M_n(__n) 03246 { } 03247 03248 _RealType 03249 n() const 03250 { return _M_n; } 03251 03252 friend bool 03253 operator==(const param_type& __p1, const param_type& __p2) 03254 { return __p1._M_n == __p2._M_n; } 03255 03256 friend bool 03257 operator!=(const param_type& __p1, const param_type& __p2) 03258 { return !(__p1 == __p2); } 03259 03260 private: 03261 _RealType _M_n; 03262 }; 03263 03264 explicit 03265 student_t_distribution(_RealType __n = _RealType(1)) 03266 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2) 03267 { } 03268 03269 explicit 03270 student_t_distribution(const param_type& __p) 03271 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2) 03272 { } 03273 03274 /** 03275 * @brief Resets the distribution state. 03276 */ 03277 void 03278 reset() 03279 { 03280 _M_nd.reset(); 03281 _M_gd.reset(); 03282 } 03283 03284 /** 03285 * 03286 */ 03287 _RealType 03288 n() const 03289 { return _M_param.n(); } 03290 03291 /** 03292 * @brief Returns the parameter set of the distribution. 03293 */ 03294 param_type 03295 param() const 03296 { return _M_param; } 03297 03298 /** 03299 * @brief Sets the parameter set of the distribution. 03300 * @param __param The new parameter set of the distribution. 03301 */ 03302 void 03303 param(const param_type& __param) 03304 { _M_param = __param; } 03305 03306 /** 03307 * @brief Returns the greatest lower bound value of the distribution. 03308 */ 03309 result_type 03310 min() const 03311 { return std::numeric_limits<result_type>::lowest(); } 03312 03313 /** 03314 * @brief Returns the least upper bound value of the distribution. 03315 */ 03316 result_type 03317 max() const 03318 { return std::numeric_limits<result_type>::max(); } 03319 03320 /** 03321 * @brief Generating functions. 03322 */ 03323 template<typename _UniformRandomNumberGenerator> 03324 result_type 03325 operator()(_UniformRandomNumberGenerator& __urng) 03326 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); } 03327 03328 template<typename _UniformRandomNumberGenerator> 03329 result_type 03330 operator()(_UniformRandomNumberGenerator& __urng, 03331 const param_type& __p) 03332 { 03333 typedef typename std::gamma_distribution<result_type>::param_type 03334 param_type; 03335 03336 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2)); 03337 return _M_nd(__urng) * std::sqrt(__p.n() / __g); 03338 } 03339 03340 template<typename _ForwardIterator, 03341 typename _UniformRandomNumberGenerator> 03342 void 03343 __generate(_ForwardIterator __f, _ForwardIterator __t, 03344 _UniformRandomNumberGenerator& __urng) 03345 { this->__generate_impl(__f, __t, __urng); } 03346 03347 template<typename _ForwardIterator, 03348 typename _UniformRandomNumberGenerator> 03349 void 03350 __generate(_ForwardIterator __f, _ForwardIterator __t, 03351 _UniformRandomNumberGenerator& __urng, 03352 const param_type& __p) 03353 { this->__generate_impl(__f, __t, __urng, __p); } 03354 03355 template<typename _UniformRandomNumberGenerator> 03356 void 03357 __generate(result_type* __f, result_type* __t, 03358 _UniformRandomNumberGenerator& __urng) 03359 { this->__generate_impl(__f, __t, __urng); } 03360 03361 template<typename _UniformRandomNumberGenerator> 03362 void 03363 __generate(result_type* __f, result_type* __t, 03364 _UniformRandomNumberGenerator& __urng, 03365 const param_type& __p) 03366 { this->__generate_impl(__f, __t, __urng, __p); } 03367 03368 /** 03369 * @brief Return true if two Student t distributions have 03370 * the same parameters and the sequences that would 03371 * be generated are equal. 03372 */ 03373 friend bool 03374 operator==(const student_t_distribution& __d1, 03375 const student_t_distribution& __d2) 03376 { return (__d1._M_param == __d2._M_param 03377 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); } 03378 03379 /** 03380 * @brief Inserts a %student_t_distribution random number distribution 03381 * @p __x into the output stream @p __os. 03382 * 03383 * @param __os An output stream. 03384 * @param __x A %student_t_distribution random number distribution. 03385 * 03386 * @returns The output stream with the state of @p __x inserted or in 03387 * an error state. 03388 */ 03389 template<typename _RealType1, typename _CharT, typename _Traits> 03390 friend std::basic_ostream<_CharT, _Traits>& 03391 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 03392 const std::student_t_distribution<_RealType1>& __x); 03393 03394 /** 03395 * @brief Extracts a %student_t_distribution random number distribution 03396 * @p __x from the input stream @p __is. 03397 * 03398 * @param __is An input stream. 03399 * @param __x A %student_t_distribution random number 03400 * generator engine. 03401 * 03402 * @returns The input stream with @p __x extracted or in an error state. 03403 */ 03404 template<typename _RealType1, typename _CharT, typename _Traits> 03405 friend std::basic_istream<_CharT, _Traits>& 03406 operator>>(std::basic_istream<_CharT, _Traits>& __is, 03407 std::student_t_distribution<_RealType1>& __x); 03408 03409 private: 03410 template<typename _ForwardIterator, 03411 typename _UniformRandomNumberGenerator> 03412 void 03413 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03414 _UniformRandomNumberGenerator& __urng); 03415 template<typename _ForwardIterator, 03416 typename _UniformRandomNumberGenerator> 03417 void 03418 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03419 _UniformRandomNumberGenerator& __urng, 03420 const param_type& __p); 03421 03422 param_type _M_param; 03423 03424 std::normal_distribution<result_type> _M_nd; 03425 std::gamma_distribution<result_type> _M_gd; 03426 }; 03427 03428 /** 03429 * @brief Return true if two Student t distributions are different. 03430 */ 03431 template<typename _RealType> 03432 inline bool 03433 operator!=(const std::student_t_distribution<_RealType>& __d1, 03434 const std::student_t_distribution<_RealType>& __d2) 03435 { return !(__d1 == __d2); } 03436 03437 03438 /* @} */ // group random_distributions_normal 03439 03440 /** 03441 * @addtogroup random_distributions_bernoulli Bernoulli Distributions 03442 * @ingroup random_distributions 03443 * @{ 03444 */ 03445 03446 /** 03447 * @brief A Bernoulli random number distribution. 03448 * 03449 * Generates a sequence of true and false values with likelihood @f$p@f$ 03450 * that true will come up and @f$(1 - p)@f$ that false will appear. 03451 */ 03452 class bernoulli_distribution 03453 { 03454 public: 03455 /** The type of the range of the distribution. */ 03456 typedef bool result_type; 03457 03458 /** Parameter type. */ 03459 struct param_type 03460 { 03461 typedef bernoulli_distribution distribution_type; 03462 03463 explicit 03464 param_type(double __p = 0.5) 03465 : _M_p(__p) 03466 { 03467 __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0)); 03468 } 03469 03470 double 03471 p() const 03472 { return _M_p; } 03473 03474 friend bool 03475 operator==(const param_type& __p1, const param_type& __p2) 03476 { return __p1._M_p == __p2._M_p; } 03477 03478 friend bool 03479 operator!=(const param_type& __p1, const param_type& __p2) 03480 { return !(__p1 == __p2); } 03481 03482 private: 03483 double _M_p; 03484 }; 03485 03486 public: 03487 /** 03488 * @brief Constructs a Bernoulli distribution with likelihood @p p. 03489 * 03490 * @param __p [IN] The likelihood of a true result being returned. 03491 * Must be in the interval @f$[0, 1]@f$. 03492 */ 03493 explicit 03494 bernoulli_distribution(double __p = 0.5) 03495 : _M_param(__p) 03496 { } 03497 03498 explicit 03499 bernoulli_distribution(const param_type& __p) 03500 : _M_param(__p) 03501 { } 03502 03503 /** 03504 * @brief Resets the distribution state. 03505 * 03506 * Does nothing for a Bernoulli distribution. 03507 */ 03508 void 03509 reset() { } 03510 03511 /** 03512 * @brief Returns the @p p parameter of the distribution. 03513 */ 03514 double 03515 p() const 03516 { return _M_param.p(); } 03517 03518 /** 03519 * @brief Returns the parameter set of the distribution. 03520 */ 03521 param_type 03522 param() const 03523 { return _M_param; } 03524 03525 /** 03526 * @brief Sets the parameter set of the distribution. 03527 * @param __param The new parameter set of the distribution. 03528 */ 03529 void 03530 param(const param_type& __param) 03531 { _M_param = __param; } 03532 03533 /** 03534 * @brief Returns the greatest lower bound value of the distribution. 03535 */ 03536 result_type 03537 min() const 03538 { return std::numeric_limits<result_type>::min(); } 03539 03540 /** 03541 * @brief Returns the least upper bound value of the distribution. 03542 */ 03543 result_type 03544 max() const 03545 { return std::numeric_limits<result_type>::max(); } 03546 03547 /** 03548 * @brief Generating functions. 03549 */ 03550 template<typename _UniformRandomNumberGenerator> 03551 result_type 03552 operator()(_UniformRandomNumberGenerator& __urng) 03553 { return this->operator()(__urng, _M_param); } 03554 03555 template<typename _UniformRandomNumberGenerator> 03556 result_type 03557 operator()(_UniformRandomNumberGenerator& __urng, 03558 const param_type& __p) 03559 { 03560 __detail::_Adaptor<_UniformRandomNumberGenerator, double> 03561 __aurng(__urng); 03562 if ((__aurng() - __aurng.min()) 03563 < __p.p() * (__aurng.max() - __aurng.min())) 03564 return true; 03565 return false; 03566 } 03567 03568 template<typename _ForwardIterator, 03569 typename _UniformRandomNumberGenerator> 03570 void 03571 __generate(_ForwardIterator __f, _ForwardIterator __t, 03572 _UniformRandomNumberGenerator& __urng) 03573 { this->__generate(__f, __t, __urng, _M_param); } 03574 03575 template<typename _ForwardIterator, 03576 typename _UniformRandomNumberGenerator> 03577 void 03578 __generate(_ForwardIterator __f, _ForwardIterator __t, 03579 _UniformRandomNumberGenerator& __urng, const param_type& __p) 03580 { this->__generate_impl(__f, __t, __urng, __p); } 03581 03582 template<typename _UniformRandomNumberGenerator> 03583 void 03584 __generate(result_type* __f, result_type* __t, 03585 _UniformRandomNumberGenerator& __urng, 03586 const param_type& __p) 03587 { this->__generate_impl(__f, __t, __urng, __p); } 03588 03589 /** 03590 * @brief Return true if two Bernoulli distributions have 03591 * the same parameters. 03592 */ 03593 friend bool 03594 operator==(const bernoulli_distribution& __d1, 03595 const bernoulli_distribution& __d2) 03596 { return __d1._M_param == __d2._M_param; } 03597 03598 private: 03599 template<typename _ForwardIterator, 03600 typename _UniformRandomNumberGenerator> 03601 void 03602 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03603 _UniformRandomNumberGenerator& __urng, 03604 const param_type& __p); 03605 03606 param_type _M_param; 03607 }; 03608 03609 /** 03610 * @brief Return true if two Bernoulli distributions have 03611 * different parameters. 03612 */ 03613 inline bool 03614 operator!=(const std::bernoulli_distribution& __d1, 03615 const std::bernoulli_distribution& __d2) 03616 { return !(__d1 == __d2); } 03617 03618 /** 03619 * @brief Inserts a %bernoulli_distribution random number distribution 03620 * @p __x into the output stream @p __os. 03621 * 03622 * @param __os An output stream. 03623 * @param __x A %bernoulli_distribution random number distribution. 03624 * 03625 * @returns The output stream with the state of @p __x inserted or in 03626 * an error state. 03627 */ 03628 template<typename _CharT, typename _Traits> 03629 std::basic_ostream<_CharT, _Traits>& 03630 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 03631 const std::bernoulli_distribution& __x); 03632 03633 /** 03634 * @brief Extracts a %bernoulli_distribution random number distribution 03635 * @p __x from the input stream @p __is. 03636 * 03637 * @param __is An input stream. 03638 * @param __x A %bernoulli_distribution random number generator engine. 03639 * 03640 * @returns The input stream with @p __x extracted or in an error state. 03641 */ 03642 template<typename _CharT, typename _Traits> 03643 std::basic_istream<_CharT, _Traits>& 03644 operator>>(std::basic_istream<_CharT, _Traits>& __is, 03645 std::bernoulli_distribution& __x) 03646 { 03647 double __p; 03648 __is >> __p; 03649 __x.param(bernoulli_distribution::param_type(__p)); 03650 return __is; 03651 } 03652 03653 03654 /** 03655 * @brief A discrete binomial random number distribution. 03656 * 03657 * The formula for the binomial probability density function is 03658 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$ 03659 * and @f$p@f$ are the parameters of the distribution. 03660 */ 03661 template<typename _IntType = int> 03662 class binomial_distribution 03663 { 03664 static_assert(std::is_integral<_IntType>::value, 03665 "result_type must be an integral type"); 03666 03667 public: 03668 /** The type of the range of the distribution. */ 03669 typedef _IntType result_type; 03670 03671 /** Parameter type. */ 03672 struct param_type 03673 { 03674 typedef binomial_distribution<_IntType> distribution_type; 03675 friend class binomial_distribution<_IntType>; 03676 03677 explicit 03678 param_type(_IntType __t = _IntType(1), double __p = 0.5) 03679 : _M_t(__t), _M_p(__p) 03680 { 03681 __glibcxx_assert((_M_t >= _IntType(0)) 03682 && (_M_p >= 0.0) 03683 && (_M_p <= 1.0)); 03684 _M_initialize(); 03685 } 03686 03687 _IntType 03688 t() const 03689 { return _M_t; } 03690 03691 double 03692 p() const 03693 { return _M_p; } 03694 03695 friend bool 03696 operator==(const param_type& __p1, const param_type& __p2) 03697 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; } 03698 03699 friend bool 03700 operator!=(const param_type& __p1, const param_type& __p2) 03701 { return !(__p1 == __p2); } 03702 03703 private: 03704 void 03705 _M_initialize(); 03706 03707 _IntType _M_t; 03708 double _M_p; 03709 03710 double _M_q; 03711 #if _GLIBCXX_USE_C99_MATH_TR1 03712 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c, 03713 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; 03714 #endif 03715 bool _M_easy; 03716 }; 03717 03718 // constructors and member function 03719 explicit 03720 binomial_distribution(_IntType __t = _IntType(1), 03721 double __p = 0.5) 03722 : _M_param(__t, __p), _M_nd() 03723 { } 03724 03725 explicit 03726 binomial_distribution(const param_type& __p) 03727 : _M_param(__p), _M_nd() 03728 { } 03729 03730 /** 03731 * @brief Resets the distribution state. 03732 */ 03733 void 03734 reset() 03735 { _M_nd.reset(); } 03736 03737 /** 03738 * @brief Returns the distribution @p t parameter. 03739 */ 03740 _IntType 03741 t() const 03742 { return _M_param.t(); } 03743 03744 /** 03745 * @brief Returns the distribution @p p parameter. 03746 */ 03747 double 03748 p() const 03749 { return _M_param.p(); } 03750 03751 /** 03752 * @brief Returns the parameter set of the distribution. 03753 */ 03754 param_type 03755 param() const 03756 { return _M_param; } 03757 03758 /** 03759 * @brief Sets the parameter set of the distribution. 03760 * @param __param The new parameter set of the distribution. 03761 */ 03762 void 03763 param(const param_type& __param) 03764 { _M_param = __param; } 03765 03766 /** 03767 * @brief Returns the greatest lower bound value of the distribution. 03768 */ 03769 result_type 03770 min() const 03771 { return 0; } 03772 03773 /** 03774 * @brief Returns the least upper bound value of the distribution. 03775 */ 03776 result_type 03777 max() const 03778 { return _M_param.t(); } 03779 03780 /** 03781 * @brief Generating functions. 03782 */ 03783 template<typename _UniformRandomNumberGenerator> 03784 result_type 03785 operator()(_UniformRandomNumberGenerator& __urng) 03786 { return this->operator()(__urng, _M_param); } 03787 03788 template<typename _UniformRandomNumberGenerator> 03789 result_type 03790 operator()(_UniformRandomNumberGenerator& __urng, 03791 const param_type& __p); 03792 03793 template<typename _ForwardIterator, 03794 typename _UniformRandomNumberGenerator> 03795 void 03796 __generate(_ForwardIterator __f, _ForwardIterator __t, 03797 _UniformRandomNumberGenerator& __urng) 03798 { this->__generate(__f, __t, __urng, _M_param); } 03799 03800 template<typename _ForwardIterator, 03801 typename _UniformRandomNumberGenerator> 03802 void 03803 __generate(_ForwardIterator __f, _ForwardIterator __t, 03804 _UniformRandomNumberGenerator& __urng, 03805 const param_type& __p) 03806 { this->__generate_impl(__f, __t, __urng, __p); } 03807 03808 template<typename _UniformRandomNumberGenerator> 03809 void 03810 __generate(result_type* __f, result_type* __t, 03811 _UniformRandomNumberGenerator& __urng, 03812 const param_type& __p) 03813 { this->__generate_impl(__f, __t, __urng, __p); } 03814 03815 /** 03816 * @brief Return true if two binomial distributions have 03817 * the same parameters and the sequences that would 03818 * be generated are equal. 03819 */ 03820 friend bool 03821 operator==(const binomial_distribution& __d1, 03822 const binomial_distribution& __d2) 03823 #ifdef _GLIBCXX_USE_C99_MATH_TR1 03824 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; } 03825 #else 03826 { return __d1._M_param == __d2._M_param; } 03827 #endif 03828 03829 /** 03830 * @brief Inserts a %binomial_distribution random number distribution 03831 * @p __x into the output stream @p __os. 03832 * 03833 * @param __os An output stream. 03834 * @param __x A %binomial_distribution random number distribution. 03835 * 03836 * @returns The output stream with the state of @p __x inserted or in 03837 * an error state. 03838 */ 03839 template<typename _IntType1, 03840 typename _CharT, typename _Traits> 03841 friend std::basic_ostream<_CharT, _Traits>& 03842 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 03843 const std::binomial_distribution<_IntType1>& __x); 03844 03845 /** 03846 * @brief Extracts a %binomial_distribution random number distribution 03847 * @p __x from the input stream @p __is. 03848 * 03849 * @param __is An input stream. 03850 * @param __x A %binomial_distribution random number generator engine. 03851 * 03852 * @returns The input stream with @p __x extracted or in an error 03853 * state. 03854 */ 03855 template<typename _IntType1, 03856 typename _CharT, typename _Traits> 03857 friend std::basic_istream<_CharT, _Traits>& 03858 operator>>(std::basic_istream<_CharT, _Traits>& __is, 03859 std::binomial_distribution<_IntType1>& __x); 03860 03861 private: 03862 template<typename _ForwardIterator, 03863 typename _UniformRandomNumberGenerator> 03864 void 03865 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 03866 _UniformRandomNumberGenerator& __urng, 03867 const param_type& __p); 03868 03869 template<typename _UniformRandomNumberGenerator> 03870 result_type 03871 _M_waiting(_UniformRandomNumberGenerator& __urng, 03872 _IntType __t, double __q); 03873 03874 param_type _M_param; 03875 03876 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. 03877 std::normal_distribution<double> _M_nd; 03878 }; 03879 03880 /** 03881 * @brief Return true if two binomial distributions are different. 03882 */ 03883 template<typename _IntType> 03884 inline bool 03885 operator!=(const std::binomial_distribution<_IntType>& __d1, 03886 const std::binomial_distribution<_IntType>& __d2) 03887 { return !(__d1 == __d2); } 03888 03889 03890 /** 03891 * @brief A discrete geometric random number distribution. 03892 * 03893 * The formula for the geometric probability density function is 03894 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the 03895 * distribution. 03896 */ 03897 template<typename _IntType = int> 03898 class geometric_distribution 03899 { 03900 static_assert(std::is_integral<_IntType>::value, 03901 "result_type must be an integral type"); 03902 03903 public: 03904 /** The type of the range of the distribution. */ 03905 typedef _IntType result_type; 03906 03907 /** Parameter type. */ 03908 struct param_type 03909 { 03910 typedef geometric_distribution<_IntType> distribution_type; 03911 friend class geometric_distribution<_IntType>; 03912 03913 explicit 03914 param_type(double __p = 0.5) 03915 : _M_p(__p) 03916 { 03917 __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0)); 03918 _M_initialize(); 03919 } 03920 03921 double 03922 p() const 03923 { return _M_p; } 03924 03925 friend bool 03926 operator==(const param_type& __p1, const param_type& __p2) 03927 { return __p1._M_p == __p2._M_p; } 03928 03929 friend bool 03930 operator!=(const param_type& __p1, const param_type& __p2) 03931 { return !(__p1 == __p2); } 03932 03933 private: 03934 void 03935 _M_initialize() 03936 { _M_log_1_p = std::log(1.0 - _M_p); } 03937 03938 double _M_p; 03939 03940 double _M_log_1_p; 03941 }; 03942 03943 // constructors and member function 03944 explicit 03945 geometric_distribution(double __p = 0.5) 03946 : _M_param(__p) 03947 { } 03948 03949 explicit 03950 geometric_distribution(const param_type& __p) 03951 : _M_param(__p) 03952 { } 03953 03954 /** 03955 * @brief Resets the distribution state. 03956 * 03957 * Does nothing for the geometric distribution. 03958 */ 03959 void 03960 reset() { } 03961 03962 /** 03963 * @brief Returns the distribution parameter @p p. 03964 */ 03965 double 03966 p() const 03967 { return _M_param.p(); } 03968 03969 /** 03970 * @brief Returns the parameter set of the distribution. 03971 */ 03972 param_type 03973 param() const 03974 { return _M_param; } 03975 03976 /** 03977 * @brief Sets the parameter set of the distribution. 03978 * @param __param The new parameter set of the distribution. 03979 */ 03980 void 03981 param(const param_type& __param) 03982 { _M_param = __param; } 03983 03984 /** 03985 * @brief Returns the greatest lower bound value of the distribution. 03986 */ 03987 result_type 03988 min() const 03989 { return 0; } 03990 03991 /** 03992 * @brief Returns the least upper bound value of the distribution. 03993 */ 03994 result_type 03995 max() const 03996 { return std::numeric_limits<result_type>::max(); } 03997 03998 /** 03999 * @brief Generating functions. 04000 */ 04001 template<typename _UniformRandomNumberGenerator> 04002 result_type 04003 operator()(_UniformRandomNumberGenerator& __urng) 04004 { return this->operator()(__urng, _M_param); } 04005 04006 template<typename _UniformRandomNumberGenerator> 04007 result_type 04008 operator()(_UniformRandomNumberGenerator& __urng, 04009 const param_type& __p); 04010 04011 template<typename _ForwardIterator, 04012 typename _UniformRandomNumberGenerator> 04013 void 04014 __generate(_ForwardIterator __f, _ForwardIterator __t, 04015 _UniformRandomNumberGenerator& __urng) 04016 { this->__generate(__f, __t, __urng, _M_param); } 04017 04018 template<typename _ForwardIterator, 04019 typename _UniformRandomNumberGenerator> 04020 void 04021 __generate(_ForwardIterator __f, _ForwardIterator __t, 04022 _UniformRandomNumberGenerator& __urng, 04023 const param_type& __p) 04024 { this->__generate_impl(__f, __t, __urng, __p); } 04025 04026 template<typename _UniformRandomNumberGenerator> 04027 void 04028 __generate(result_type* __f, result_type* __t, 04029 _UniformRandomNumberGenerator& __urng, 04030 const param_type& __p) 04031 { this->__generate_impl(__f, __t, __urng, __p); } 04032 04033 /** 04034 * @brief Return true if two geometric distributions have 04035 * the same parameters. 04036 */ 04037 friend bool 04038 operator==(const geometric_distribution& __d1, 04039 const geometric_distribution& __d2) 04040 { return __d1._M_param == __d2._M_param; } 04041 04042 private: 04043 template<typename _ForwardIterator, 04044 typename _UniformRandomNumberGenerator> 04045 void 04046 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04047 _UniformRandomNumberGenerator& __urng, 04048 const param_type& __p); 04049 04050 param_type _M_param; 04051 }; 04052 04053 /** 04054 * @brief Return true if two geometric distributions have 04055 * different parameters. 04056 */ 04057 template<typename _IntType> 04058 inline bool 04059 operator!=(const std::geometric_distribution<_IntType>& __d1, 04060 const std::geometric_distribution<_IntType>& __d2) 04061 { return !(__d1 == __d2); } 04062 04063 /** 04064 * @brief Inserts a %geometric_distribution random number distribution 04065 * @p __x into the output stream @p __os. 04066 * 04067 * @param __os An output stream. 04068 * @param __x A %geometric_distribution random number distribution. 04069 * 04070 * @returns The output stream with the state of @p __x inserted or in 04071 * an error state. 04072 */ 04073 template<typename _IntType, 04074 typename _CharT, typename _Traits> 04075 std::basic_ostream<_CharT, _Traits>& 04076 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 04077 const std::geometric_distribution<_IntType>& __x); 04078 04079 /** 04080 * @brief Extracts a %geometric_distribution random number distribution 04081 * @p __x from the input stream @p __is. 04082 * 04083 * @param __is An input stream. 04084 * @param __x A %geometric_distribution random number generator engine. 04085 * 04086 * @returns The input stream with @p __x extracted or in an error state. 04087 */ 04088 template<typename _IntType, 04089 typename _CharT, typename _Traits> 04090 std::basic_istream<_CharT, _Traits>& 04091 operator>>(std::basic_istream<_CharT, _Traits>& __is, 04092 std::geometric_distribution<_IntType>& __x); 04093 04094 04095 /** 04096 * @brief A negative_binomial_distribution random number distribution. 04097 * 04098 * The formula for the negative binomial probability mass function is 04099 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$ 04100 * and @f$p@f$ are the parameters of the distribution. 04101 */ 04102 template<typename _IntType = int> 04103 class negative_binomial_distribution 04104 { 04105 static_assert(std::is_integral<_IntType>::value, 04106 "result_type must be an integral type"); 04107 04108 public: 04109 /** The type of the range of the distribution. */ 04110 typedef _IntType result_type; 04111 04112 /** Parameter type. */ 04113 struct param_type 04114 { 04115 typedef negative_binomial_distribution<_IntType> distribution_type; 04116 04117 explicit 04118 param_type(_IntType __k = 1, double __p = 0.5) 04119 : _M_k(__k), _M_p(__p) 04120 { 04121 __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0)); 04122 } 04123 04124 _IntType 04125 k() const 04126 { return _M_k; } 04127 04128 double 04129 p() const 04130 { return _M_p; } 04131 04132 friend bool 04133 operator==(const param_type& __p1, const param_type& __p2) 04134 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; } 04135 04136 friend bool 04137 operator!=(const param_type& __p1, const param_type& __p2) 04138 { return !(__p1 == __p2); } 04139 04140 private: 04141 _IntType _M_k; 04142 double _M_p; 04143 }; 04144 04145 explicit 04146 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5) 04147 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p) 04148 { } 04149 04150 explicit 04151 negative_binomial_distribution(const param_type& __p) 04152 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p()) 04153 { } 04154 04155 /** 04156 * @brief Resets the distribution state. 04157 */ 04158 void 04159 reset() 04160 { _M_gd.reset(); } 04161 04162 /** 04163 * @brief Return the @f$k@f$ parameter of the distribution. 04164 */ 04165 _IntType 04166 k() const 04167 { return _M_param.k(); } 04168 04169 /** 04170 * @brief Return the @f$p@f$ parameter of the distribution. 04171 */ 04172 double 04173 p() const 04174 { return _M_param.p(); } 04175 04176 /** 04177 * @brief Returns the parameter set of the distribution. 04178 */ 04179 param_type 04180 param() const 04181 { return _M_param; } 04182 04183 /** 04184 * @brief Sets the parameter set of the distribution. 04185 * @param __param The new parameter set of the distribution. 04186 */ 04187 void 04188 param(const param_type& __param) 04189 { _M_param = __param; } 04190 04191 /** 04192 * @brief Returns the greatest lower bound value of the distribution. 04193 */ 04194 result_type 04195 min() const 04196 { return result_type(0); } 04197 04198 /** 04199 * @brief Returns the least upper bound value of the distribution. 04200 */ 04201 result_type 04202 max() const 04203 { return std::numeric_limits<result_type>::max(); } 04204 04205 /** 04206 * @brief Generating functions. 04207 */ 04208 template<typename _UniformRandomNumberGenerator> 04209 result_type 04210 operator()(_UniformRandomNumberGenerator& __urng); 04211 04212 template<typename _UniformRandomNumberGenerator> 04213 result_type 04214 operator()(_UniformRandomNumberGenerator& __urng, 04215 const param_type& __p); 04216 04217 template<typename _ForwardIterator, 04218 typename _UniformRandomNumberGenerator> 04219 void 04220 __generate(_ForwardIterator __f, _ForwardIterator __t, 04221 _UniformRandomNumberGenerator& __urng) 04222 { this->__generate_impl(__f, __t, __urng); } 04223 04224 template<typename _ForwardIterator, 04225 typename _UniformRandomNumberGenerator> 04226 void 04227 __generate(_ForwardIterator __f, _ForwardIterator __t, 04228 _UniformRandomNumberGenerator& __urng, 04229 const param_type& __p) 04230 { this->__generate_impl(__f, __t, __urng, __p); } 04231 04232 template<typename _UniformRandomNumberGenerator> 04233 void 04234 __generate(result_type* __f, result_type* __t, 04235 _UniformRandomNumberGenerator& __urng) 04236 { this->__generate_impl(__f, __t, __urng); } 04237 04238 template<typename _UniformRandomNumberGenerator> 04239 void 04240 __generate(result_type* __f, result_type* __t, 04241 _UniformRandomNumberGenerator& __urng, 04242 const param_type& __p) 04243 { this->__generate_impl(__f, __t, __urng, __p); } 04244 04245 /** 04246 * @brief Return true if two negative binomial distributions have 04247 * the same parameters and the sequences that would be 04248 * generated are equal. 04249 */ 04250 friend bool 04251 operator==(const negative_binomial_distribution& __d1, 04252 const negative_binomial_distribution& __d2) 04253 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; } 04254 04255 /** 04256 * @brief Inserts a %negative_binomial_distribution random 04257 * number distribution @p __x into the output stream @p __os. 04258 * 04259 * @param __os An output stream. 04260 * @param __x A %negative_binomial_distribution random number 04261 * distribution. 04262 * 04263 * @returns The output stream with the state of @p __x inserted or in 04264 * an error state. 04265 */ 04266 template<typename _IntType1, typename _CharT, typename _Traits> 04267 friend std::basic_ostream<_CharT, _Traits>& 04268 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 04269 const std::negative_binomial_distribution<_IntType1>& __x); 04270 04271 /** 04272 * @brief Extracts a %negative_binomial_distribution random number 04273 * distribution @p __x from the input stream @p __is. 04274 * 04275 * @param __is An input stream. 04276 * @param __x A %negative_binomial_distribution random number 04277 * generator engine. 04278 * 04279 * @returns The input stream with @p __x extracted or in an error state. 04280 */ 04281 template<typename _IntType1, typename _CharT, typename _Traits> 04282 friend std::basic_istream<_CharT, _Traits>& 04283 operator>>(std::basic_istream<_CharT, _Traits>& __is, 04284 std::negative_binomial_distribution<_IntType1>& __x); 04285 04286 private: 04287 template<typename _ForwardIterator, 04288 typename _UniformRandomNumberGenerator> 04289 void 04290 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04291 _UniformRandomNumberGenerator& __urng); 04292 template<typename _ForwardIterator, 04293 typename _UniformRandomNumberGenerator> 04294 void 04295 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04296 _UniformRandomNumberGenerator& __urng, 04297 const param_type& __p); 04298 04299 param_type _M_param; 04300 04301 std::gamma_distribution<double> _M_gd; 04302 }; 04303 04304 /** 04305 * @brief Return true if two negative binomial distributions are different. 04306 */ 04307 template<typename _IntType> 04308 inline bool 04309 operator!=(const std::negative_binomial_distribution<_IntType>& __d1, 04310 const std::negative_binomial_distribution<_IntType>& __d2) 04311 { return !(__d1 == __d2); } 04312 04313 04314 /* @} */ // group random_distributions_bernoulli 04315 04316 /** 04317 * @addtogroup random_distributions_poisson Poisson Distributions 04318 * @ingroup random_distributions 04319 * @{ 04320 */ 04321 04322 /** 04323 * @brief A discrete Poisson random number distribution. 04324 * 04325 * The formula for the Poisson probability density function is 04326 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the 04327 * parameter of the distribution. 04328 */ 04329 template<typename _IntType = int> 04330 class poisson_distribution 04331 { 04332 static_assert(std::is_integral<_IntType>::value, 04333 "result_type must be an integral type"); 04334 04335 public: 04336 /** The type of the range of the distribution. */ 04337 typedef _IntType result_type; 04338 04339 /** Parameter type. */ 04340 struct param_type 04341 { 04342 typedef poisson_distribution<_IntType> distribution_type; 04343 friend class poisson_distribution<_IntType>; 04344 04345 explicit 04346 param_type(double __mean = 1.0) 04347 : _M_mean(__mean) 04348 { 04349 __glibcxx_assert(_M_mean > 0.0); 04350 _M_initialize(); 04351 } 04352 04353 double 04354 mean() const 04355 { return _M_mean; } 04356 04357 friend bool 04358 operator==(const param_type& __p1, const param_type& __p2) 04359 { return __p1._M_mean == __p2._M_mean; } 04360 04361 friend bool 04362 operator!=(const param_type& __p1, const param_type& __p2) 04363 { return !(__p1 == __p2); } 04364 04365 private: 04366 // Hosts either log(mean) or the threshold of the simple method. 04367 void 04368 _M_initialize(); 04369 04370 double _M_mean; 04371 04372 double _M_lm_thr; 04373 #if _GLIBCXX_USE_C99_MATH_TR1 04374 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; 04375 #endif 04376 }; 04377 04378 // constructors and member function 04379 explicit 04380 poisson_distribution(double __mean = 1.0) 04381 : _M_param(__mean), _M_nd() 04382 { } 04383 04384 explicit 04385 poisson_distribution(const param_type& __p) 04386 : _M_param(__p), _M_nd() 04387 { } 04388 04389 /** 04390 * @brief Resets the distribution state. 04391 */ 04392 void 04393 reset() 04394 { _M_nd.reset(); } 04395 04396 /** 04397 * @brief Returns the distribution parameter @p mean. 04398 */ 04399 double 04400 mean() const 04401 { return _M_param.mean(); } 04402 04403 /** 04404 * @brief Returns the parameter set of the distribution. 04405 */ 04406 param_type 04407 param() const 04408 { return _M_param; } 04409 04410 /** 04411 * @brief Sets the parameter set of the distribution. 04412 * @param __param The new parameter set of the distribution. 04413 */ 04414 void 04415 param(const param_type& __param) 04416 { _M_param = __param; } 04417 04418 /** 04419 * @brief Returns the greatest lower bound value of the distribution. 04420 */ 04421 result_type 04422 min() const 04423 { return 0; } 04424 04425 /** 04426 * @brief Returns the least upper bound value of the distribution. 04427 */ 04428 result_type 04429 max() const 04430 { return std::numeric_limits<result_type>::max(); } 04431 04432 /** 04433 * @brief Generating functions. 04434 */ 04435 template<typename _UniformRandomNumberGenerator> 04436 result_type 04437 operator()(_UniformRandomNumberGenerator& __urng) 04438 { return this->operator()(__urng, _M_param); } 04439 04440 template<typename _UniformRandomNumberGenerator> 04441 result_type 04442 operator()(_UniformRandomNumberGenerator& __urng, 04443 const param_type& __p); 04444 04445 template<typename _ForwardIterator, 04446 typename _UniformRandomNumberGenerator> 04447 void 04448 __generate(_ForwardIterator __f, _ForwardIterator __t, 04449 _UniformRandomNumberGenerator& __urng) 04450 { this->__generate(__f, __t, __urng, _M_param); } 04451 04452 template<typename _ForwardIterator, 04453 typename _UniformRandomNumberGenerator> 04454 void 04455 __generate(_ForwardIterator __f, _ForwardIterator __t, 04456 _UniformRandomNumberGenerator& __urng, 04457 const param_type& __p) 04458 { this->__generate_impl(__f, __t, __urng, __p); } 04459 04460 template<typename _UniformRandomNumberGenerator> 04461 void 04462 __generate(result_type* __f, result_type* __t, 04463 _UniformRandomNumberGenerator& __urng, 04464 const param_type& __p) 04465 { this->__generate_impl(__f, __t, __urng, __p); } 04466 04467 /** 04468 * @brief Return true if two Poisson distributions have the same 04469 * parameters and the sequences that would be generated 04470 * are equal. 04471 */ 04472 friend bool 04473 operator==(const poisson_distribution& __d1, 04474 const poisson_distribution& __d2) 04475 #ifdef _GLIBCXX_USE_C99_MATH_TR1 04476 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; } 04477 #else 04478 { return __d1._M_param == __d2._M_param; } 04479 #endif 04480 04481 /** 04482 * @brief Inserts a %poisson_distribution random number distribution 04483 * @p __x into the output stream @p __os. 04484 * 04485 * @param __os An output stream. 04486 * @param __x A %poisson_distribution random number distribution. 04487 * 04488 * @returns The output stream with the state of @p __x inserted or in 04489 * an error state. 04490 */ 04491 template<typename _IntType1, typename _CharT, typename _Traits> 04492 friend std::basic_ostream<_CharT, _Traits>& 04493 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 04494 const std::poisson_distribution<_IntType1>& __x); 04495 04496 /** 04497 * @brief Extracts a %poisson_distribution random number distribution 04498 * @p __x from the input stream @p __is. 04499 * 04500 * @param __is An input stream. 04501 * @param __x A %poisson_distribution random number generator engine. 04502 * 04503 * @returns The input stream with @p __x extracted or in an error 04504 * state. 04505 */ 04506 template<typename _IntType1, typename _CharT, typename _Traits> 04507 friend std::basic_istream<_CharT, _Traits>& 04508 operator>>(std::basic_istream<_CharT, _Traits>& __is, 04509 std::poisson_distribution<_IntType1>& __x); 04510 04511 private: 04512 template<typename _ForwardIterator, 04513 typename _UniformRandomNumberGenerator> 04514 void 04515 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04516 _UniformRandomNumberGenerator& __urng, 04517 const param_type& __p); 04518 04519 param_type _M_param; 04520 04521 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. 04522 std::normal_distribution<double> _M_nd; 04523 }; 04524 04525 /** 04526 * @brief Return true if two Poisson distributions are different. 04527 */ 04528 template<typename _IntType> 04529 inline bool 04530 operator!=(const std::poisson_distribution<_IntType>& __d1, 04531 const std::poisson_distribution<_IntType>& __d2) 04532 { return !(__d1 == __d2); } 04533 04534 04535 /** 04536 * @brief An exponential continuous distribution for random numbers. 04537 * 04538 * The formula for the exponential probability density function is 04539 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$. 04540 * 04541 * <table border=1 cellpadding=10 cellspacing=0> 04542 * <caption align=top>Distribution Statistics</caption> 04543 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr> 04544 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr> 04545 * <tr><td>Mode</td><td>@f$zero@f$</td></tr> 04546 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr> 04547 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr> 04548 * </table> 04549 */ 04550 template<typename _RealType = double> 04551 class exponential_distribution 04552 { 04553 static_assert(std::is_floating_point<_RealType>::value, 04554 "result_type must be a floating point type"); 04555 04556 public: 04557 /** The type of the range of the distribution. */ 04558 typedef _RealType result_type; 04559 04560 /** Parameter type. */ 04561 struct param_type 04562 { 04563 typedef exponential_distribution<_RealType> distribution_type; 04564 04565 explicit 04566 param_type(_RealType __lambda = _RealType(1)) 04567 : _M_lambda(__lambda) 04568 { 04569 __glibcxx_assert(_M_lambda > _RealType(0)); 04570 } 04571 04572 _RealType 04573 lambda() const 04574 { return _M_lambda; } 04575 04576 friend bool 04577 operator==(const param_type& __p1, const param_type& __p2) 04578 { return __p1._M_lambda == __p2._M_lambda; } 04579 04580 friend bool 04581 operator!=(const param_type& __p1, const param_type& __p2) 04582 { return !(__p1 == __p2); } 04583 04584 private: 04585 _RealType _M_lambda; 04586 }; 04587 04588 public: 04589 /** 04590 * @brief Constructs an exponential distribution with inverse scale 04591 * parameter @f$\lambda@f$. 04592 */ 04593 explicit 04594 exponential_distribution(const result_type& __lambda = result_type(1)) 04595 : _M_param(__lambda) 04596 { } 04597 04598 explicit 04599 exponential_distribution(const param_type& __p) 04600 : _M_param(__p) 04601 { } 04602 04603 /** 04604 * @brief Resets the distribution state. 04605 * 04606 * Has no effect on exponential distributions. 04607 */ 04608 void 04609 reset() { } 04610 04611 /** 04612 * @brief Returns the inverse scale parameter of the distribution. 04613 */ 04614 _RealType 04615 lambda() const 04616 { return _M_param.lambda(); } 04617 04618 /** 04619 * @brief Returns the parameter set of the distribution. 04620 */ 04621 param_type 04622 param() const 04623 { return _M_param; } 04624 04625 /** 04626 * @brief Sets the parameter set of the distribution. 04627 * @param __param The new parameter set of the distribution. 04628 */ 04629 void 04630 param(const param_type& __param) 04631 { _M_param = __param; } 04632 04633 /** 04634 * @brief Returns the greatest lower bound value of the distribution. 04635 */ 04636 result_type 04637 min() const 04638 { return result_type(0); } 04639 04640 /** 04641 * @brief Returns the least upper bound value of the distribution. 04642 */ 04643 result_type 04644 max() const 04645 { return std::numeric_limits<result_type>::max(); } 04646 04647 /** 04648 * @brief Generating functions. 04649 */ 04650 template<typename _UniformRandomNumberGenerator> 04651 result_type 04652 operator()(_UniformRandomNumberGenerator& __urng) 04653 { return this->operator()(__urng, _M_param); } 04654 04655 template<typename _UniformRandomNumberGenerator> 04656 result_type 04657 operator()(_UniformRandomNumberGenerator& __urng, 04658 const param_type& __p) 04659 { 04660 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 04661 __aurng(__urng); 04662 return -std::log(result_type(1) - __aurng()) / __p.lambda(); 04663 } 04664 04665 template<typename _ForwardIterator, 04666 typename _UniformRandomNumberGenerator> 04667 void 04668 __generate(_ForwardIterator __f, _ForwardIterator __t, 04669 _UniformRandomNumberGenerator& __urng) 04670 { this->__generate(__f, __t, __urng, _M_param); } 04671 04672 template<typename _ForwardIterator, 04673 typename _UniformRandomNumberGenerator> 04674 void 04675 __generate(_ForwardIterator __f, _ForwardIterator __t, 04676 _UniformRandomNumberGenerator& __urng, 04677 const param_type& __p) 04678 { this->__generate_impl(__f, __t, __urng, __p); } 04679 04680 template<typename _UniformRandomNumberGenerator> 04681 void 04682 __generate(result_type* __f, result_type* __t, 04683 _UniformRandomNumberGenerator& __urng, 04684 const param_type& __p) 04685 { this->__generate_impl(__f, __t, __urng, __p); } 04686 04687 /** 04688 * @brief Return true if two exponential distributions have the same 04689 * parameters. 04690 */ 04691 friend bool 04692 operator==(const exponential_distribution& __d1, 04693 const exponential_distribution& __d2) 04694 { return __d1._M_param == __d2._M_param; } 04695 04696 private: 04697 template<typename _ForwardIterator, 04698 typename _UniformRandomNumberGenerator> 04699 void 04700 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04701 _UniformRandomNumberGenerator& __urng, 04702 const param_type& __p); 04703 04704 param_type _M_param; 04705 }; 04706 04707 /** 04708 * @brief Return true if two exponential distributions have different 04709 * parameters. 04710 */ 04711 template<typename _RealType> 04712 inline bool 04713 operator!=(const std::exponential_distribution<_RealType>& __d1, 04714 const std::exponential_distribution<_RealType>& __d2) 04715 { return !(__d1 == __d2); } 04716 04717 /** 04718 * @brief Inserts a %exponential_distribution random number distribution 04719 * @p __x into the output stream @p __os. 04720 * 04721 * @param __os An output stream. 04722 * @param __x A %exponential_distribution random number distribution. 04723 * 04724 * @returns The output stream with the state of @p __x inserted or in 04725 * an error state. 04726 */ 04727 template<typename _RealType, typename _CharT, typename _Traits> 04728 std::basic_ostream<_CharT, _Traits>& 04729 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 04730 const std::exponential_distribution<_RealType>& __x); 04731 04732 /** 04733 * @brief Extracts a %exponential_distribution random number distribution 04734 * @p __x from the input stream @p __is. 04735 * 04736 * @param __is An input stream. 04737 * @param __x A %exponential_distribution random number 04738 * generator engine. 04739 * 04740 * @returns The input stream with @p __x extracted or in an error state. 04741 */ 04742 template<typename _RealType, typename _CharT, typename _Traits> 04743 std::basic_istream<_CharT, _Traits>& 04744 operator>>(std::basic_istream<_CharT, _Traits>& __is, 04745 std::exponential_distribution<_RealType>& __x); 04746 04747 04748 /** 04749 * @brief A weibull_distribution random number distribution. 04750 * 04751 * The formula for the normal probability density function is: 04752 * @f[ 04753 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1} 04754 * \exp{(-(\frac{x}{\beta})^\alpha)} 04755 * @f] 04756 */ 04757 template<typename _RealType = double> 04758 class weibull_distribution 04759 { 04760 static_assert(std::is_floating_point<_RealType>::value, 04761 "result_type must be a floating point type"); 04762 04763 public: 04764 /** The type of the range of the distribution. */ 04765 typedef _RealType result_type; 04766 04767 /** Parameter type. */ 04768 struct param_type 04769 { 04770 typedef weibull_distribution<_RealType> distribution_type; 04771 04772 explicit 04773 param_type(_RealType __a = _RealType(1), 04774 _RealType __b = _RealType(1)) 04775 : _M_a(__a), _M_b(__b) 04776 { } 04777 04778 _RealType 04779 a() const 04780 { return _M_a; } 04781 04782 _RealType 04783 b() const 04784 { return _M_b; } 04785 04786 friend bool 04787 operator==(const param_type& __p1, const param_type& __p2) 04788 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } 04789 04790 friend bool 04791 operator!=(const param_type& __p1, const param_type& __p2) 04792 { return !(__p1 == __p2); } 04793 04794 private: 04795 _RealType _M_a; 04796 _RealType _M_b; 04797 }; 04798 04799 explicit 04800 weibull_distribution(_RealType __a = _RealType(1), 04801 _RealType __b = _RealType(1)) 04802 : _M_param(__a, __b) 04803 { } 04804 04805 explicit 04806 weibull_distribution(const param_type& __p) 04807 : _M_param(__p) 04808 { } 04809 04810 /** 04811 * @brief Resets the distribution state. 04812 */ 04813 void 04814 reset() 04815 { } 04816 04817 /** 04818 * @brief Return the @f$a@f$ parameter of the distribution. 04819 */ 04820 _RealType 04821 a() const 04822 { return _M_param.a(); } 04823 04824 /** 04825 * @brief Return the @f$b@f$ parameter of the distribution. 04826 */ 04827 _RealType 04828 b() const 04829 { return _M_param.b(); } 04830 04831 /** 04832 * @brief Returns the parameter set of the distribution. 04833 */ 04834 param_type 04835 param() const 04836 { return _M_param; } 04837 04838 /** 04839 * @brief Sets the parameter set of the distribution. 04840 * @param __param The new parameter set of the distribution. 04841 */ 04842 void 04843 param(const param_type& __param) 04844 { _M_param = __param; } 04845 04846 /** 04847 * @brief Returns the greatest lower bound value of the distribution. 04848 */ 04849 result_type 04850 min() const 04851 { return result_type(0); } 04852 04853 /** 04854 * @brief Returns the least upper bound value of the distribution. 04855 */ 04856 result_type 04857 max() const 04858 { return std::numeric_limits<result_type>::max(); } 04859 04860 /** 04861 * @brief Generating functions. 04862 */ 04863 template<typename _UniformRandomNumberGenerator> 04864 result_type 04865 operator()(_UniformRandomNumberGenerator& __urng) 04866 { return this->operator()(__urng, _M_param); } 04867 04868 template<typename _UniformRandomNumberGenerator> 04869 result_type 04870 operator()(_UniformRandomNumberGenerator& __urng, 04871 const param_type& __p); 04872 04873 template<typename _ForwardIterator, 04874 typename _UniformRandomNumberGenerator> 04875 void 04876 __generate(_ForwardIterator __f, _ForwardIterator __t, 04877 _UniformRandomNumberGenerator& __urng) 04878 { this->__generate(__f, __t, __urng, _M_param); } 04879 04880 template<typename _ForwardIterator, 04881 typename _UniformRandomNumberGenerator> 04882 void 04883 __generate(_ForwardIterator __f, _ForwardIterator __t, 04884 _UniformRandomNumberGenerator& __urng, 04885 const param_type& __p) 04886 { this->__generate_impl(__f, __t, __urng, __p); } 04887 04888 template<typename _UniformRandomNumberGenerator> 04889 void 04890 __generate(result_type* __f, result_type* __t, 04891 _UniformRandomNumberGenerator& __urng, 04892 const param_type& __p) 04893 { this->__generate_impl(__f, __t, __urng, __p); } 04894 04895 /** 04896 * @brief Return true if two Weibull distributions have the same 04897 * parameters. 04898 */ 04899 friend bool 04900 operator==(const weibull_distribution& __d1, 04901 const weibull_distribution& __d2) 04902 { return __d1._M_param == __d2._M_param; } 04903 04904 private: 04905 template<typename _ForwardIterator, 04906 typename _UniformRandomNumberGenerator> 04907 void 04908 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 04909 _UniformRandomNumberGenerator& __urng, 04910 const param_type& __p); 04911 04912 param_type _M_param; 04913 }; 04914 04915 /** 04916 * @brief Return true if two Weibull distributions have different 04917 * parameters. 04918 */ 04919 template<typename _RealType> 04920 inline bool 04921 operator!=(const std::weibull_distribution<_RealType>& __d1, 04922 const std::weibull_distribution<_RealType>& __d2) 04923 { return !(__d1 == __d2); } 04924 04925 /** 04926 * @brief Inserts a %weibull_distribution random number distribution 04927 * @p __x into the output stream @p __os. 04928 * 04929 * @param __os An output stream. 04930 * @param __x A %weibull_distribution random number distribution. 04931 * 04932 * @returns The output stream with the state of @p __x inserted or in 04933 * an error state. 04934 */ 04935 template<typename _RealType, typename _CharT, typename _Traits> 04936 std::basic_ostream<_CharT, _Traits>& 04937 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 04938 const std::weibull_distribution<_RealType>& __x); 04939 04940 /** 04941 * @brief Extracts a %weibull_distribution random number distribution 04942 * @p __x from the input stream @p __is. 04943 * 04944 * @param __is An input stream. 04945 * @param __x A %weibull_distribution random number 04946 * generator engine. 04947 * 04948 * @returns The input stream with @p __x extracted or in an error state. 04949 */ 04950 template<typename _RealType, typename _CharT, typename _Traits> 04951 std::basic_istream<_CharT, _Traits>& 04952 operator>>(std::basic_istream<_CharT, _Traits>& __is, 04953 std::weibull_distribution<_RealType>& __x); 04954 04955 04956 /** 04957 * @brief A extreme_value_distribution random number distribution. 04958 * 04959 * The formula for the normal probability mass function is 04960 * @f[ 04961 * p(x|a,b) = \frac{1}{b} 04962 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) 04963 * @f] 04964 */ 04965 template<typename _RealType = double> 04966 class extreme_value_distribution 04967 { 04968 static_assert(std::is_floating_point<_RealType>::value, 04969 "result_type must be a floating point type"); 04970 04971 public: 04972 /** The type of the range of the distribution. */ 04973 typedef _RealType result_type; 04974 04975 /** Parameter type. */ 04976 struct param_type 04977 { 04978 typedef extreme_value_distribution<_RealType> distribution_type; 04979 04980 explicit 04981 param_type(_RealType __a = _RealType(0), 04982 _RealType __b = _RealType(1)) 04983 : _M_a(__a), _M_b(__b) 04984 { } 04985 04986 _RealType 04987 a() const 04988 { return _M_a; } 04989 04990 _RealType 04991 b() const 04992 { return _M_b; } 04993 04994 friend bool 04995 operator==(const param_type& __p1, const param_type& __p2) 04996 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } 04997 04998 friend bool 04999 operator!=(const param_type& __p1, const param_type& __p2) 05000 { return !(__p1 == __p2); } 05001 05002 private: 05003 _RealType _M_a; 05004 _RealType _M_b; 05005 }; 05006 05007 explicit 05008 extreme_value_distribution(_RealType __a = _RealType(0), 05009 _RealType __b = _RealType(1)) 05010 : _M_param(__a, __b) 05011 { } 05012 05013 explicit 05014 extreme_value_distribution(const param_type& __p) 05015 : _M_param(__p) 05016 { } 05017 05018 /** 05019 * @brief Resets the distribution state. 05020 */ 05021 void 05022 reset() 05023 { } 05024 05025 /** 05026 * @brief Return the @f$a@f$ parameter of the distribution. 05027 */ 05028 _RealType 05029 a() const 05030 { return _M_param.a(); } 05031 05032 /** 05033 * @brief Return the @f$b@f$ parameter of the distribution. 05034 */ 05035 _RealType 05036 b() const 05037 { return _M_param.b(); } 05038 05039 /** 05040 * @brief Returns the parameter set of the distribution. 05041 */ 05042 param_type 05043 param() const 05044 { return _M_param; } 05045 05046 /** 05047 * @brief Sets the parameter set of the distribution. 05048 * @param __param The new parameter set of the distribution. 05049 */ 05050 void 05051 param(const param_type& __param) 05052 { _M_param = __param; } 05053 05054 /** 05055 * @brief Returns the greatest lower bound value of the distribution. 05056 */ 05057 result_type 05058 min() const 05059 { return std::numeric_limits<result_type>::lowest(); } 05060 05061 /** 05062 * @brief Returns the least upper bound value of the distribution. 05063 */ 05064 result_type 05065 max() const 05066 { return std::numeric_limits<result_type>::max(); } 05067 05068 /** 05069 * @brief Generating functions. 05070 */ 05071 template<typename _UniformRandomNumberGenerator> 05072 result_type 05073 operator()(_UniformRandomNumberGenerator& __urng) 05074 { return this->operator()(__urng, _M_param); } 05075 05076 template<typename _UniformRandomNumberGenerator> 05077 result_type 05078 operator()(_UniformRandomNumberGenerator& __urng, 05079 const param_type& __p); 05080 05081 template<typename _ForwardIterator, 05082 typename _UniformRandomNumberGenerator> 05083 void 05084 __generate(_ForwardIterator __f, _ForwardIterator __t, 05085 _UniformRandomNumberGenerator& __urng) 05086 { this->__generate(__f, __t, __urng, _M_param); } 05087 05088 template<typename _ForwardIterator, 05089 typename _UniformRandomNumberGenerator> 05090 void 05091 __generate(_ForwardIterator __f, _ForwardIterator __t, 05092 _UniformRandomNumberGenerator& __urng, 05093 const param_type& __p) 05094 { this->__generate_impl(__f, __t, __urng, __p); } 05095 05096 template<typename _UniformRandomNumberGenerator> 05097 void 05098 __generate(result_type* __f, result_type* __t, 05099 _UniformRandomNumberGenerator& __urng, 05100 const param_type& __p) 05101 { this->__generate_impl(__f, __t, __urng, __p); } 05102 05103 /** 05104 * @brief Return true if two extreme value distributions have the same 05105 * parameters. 05106 */ 05107 friend bool 05108 operator==(const extreme_value_distribution& __d1, 05109 const extreme_value_distribution& __d2) 05110 { return __d1._M_param == __d2._M_param; } 05111 05112 private: 05113 template<typename _ForwardIterator, 05114 typename _UniformRandomNumberGenerator> 05115 void 05116 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 05117 _UniformRandomNumberGenerator& __urng, 05118 const param_type& __p); 05119 05120 param_type _M_param; 05121 }; 05122 05123 /** 05124 * @brief Return true if two extreme value distributions have different 05125 * parameters. 05126 */ 05127 template<typename _RealType> 05128 inline bool 05129 operator!=(const std::extreme_value_distribution<_RealType>& __d1, 05130 const std::extreme_value_distribution<_RealType>& __d2) 05131 { return !(__d1 == __d2); } 05132 05133 /** 05134 * @brief Inserts a %extreme_value_distribution random number distribution 05135 * @p __x into the output stream @p __os. 05136 * 05137 * @param __os An output stream. 05138 * @param __x A %extreme_value_distribution random number distribution. 05139 * 05140 * @returns The output stream with the state of @p __x inserted or in 05141 * an error state. 05142 */ 05143 template<typename _RealType, typename _CharT, typename _Traits> 05144 std::basic_ostream<_CharT, _Traits>& 05145 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 05146 const std::extreme_value_distribution<_RealType>& __x); 05147 05148 /** 05149 * @brief Extracts a %extreme_value_distribution random number 05150 * distribution @p __x from the input stream @p __is. 05151 * 05152 * @param __is An input stream. 05153 * @param __x A %extreme_value_distribution random number 05154 * generator engine. 05155 * 05156 * @returns The input stream with @p __x extracted or in an error state. 05157 */ 05158 template<typename _RealType, typename _CharT, typename _Traits> 05159 std::basic_istream<_CharT, _Traits>& 05160 operator>>(std::basic_istream<_CharT, _Traits>& __is, 05161 std::extreme_value_distribution<_RealType>& __x); 05162 05163 05164 /** 05165 * @brief A discrete_distribution random number distribution. 05166 * 05167 * The formula for the discrete probability mass function is 05168 * 05169 */ 05170 template<typename _IntType = int> 05171 class discrete_distribution 05172 { 05173 static_assert(std::is_integral<_IntType>::value, 05174 "result_type must be an integral type"); 05175 05176 public: 05177 /** The type of the range of the distribution. */ 05178 typedef _IntType result_type; 05179 05180 /** Parameter type. */ 05181 struct param_type 05182 { 05183 typedef discrete_distribution<_IntType> distribution_type; 05184 friend class discrete_distribution<_IntType>; 05185 05186 param_type() 05187 : _M_prob(), _M_cp() 05188 { } 05189 05190 template<typename _InputIterator> 05191 param_type(_InputIterator __wbegin, 05192 _InputIterator __wend) 05193 : _M_prob(__wbegin, __wend), _M_cp() 05194 { _M_initialize(); } 05195 05196 param_type(initializer_list<double> __wil) 05197 : _M_prob(__wil.begin(), __wil.end()), _M_cp() 05198 { _M_initialize(); } 05199 05200 template<typename _Func> 05201 param_type(size_t __nw, double __xmin, double __xmax, 05202 _Func __fw); 05203 05204 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/ 05205 param_type(const param_type&) = default; 05206 param_type& operator=(const param_type&) = default; 05207 05208 std::vector<double> 05209 probabilities() const 05210 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; } 05211 05212 friend bool 05213 operator==(const param_type& __p1, const param_type& __p2) 05214 { return __p1._M_prob == __p2._M_prob; } 05215 05216 friend bool 05217 operator!=(const param_type& __p1, const param_type& __p2) 05218 { return !(__p1 == __p2); } 05219 05220 private: 05221 void 05222 _M_initialize(); 05223 05224 std::vector<double> _M_prob; 05225 std::vector<double> _M_cp; 05226 }; 05227 05228 discrete_distribution() 05229 : _M_param() 05230 { } 05231 05232 template<typename _InputIterator> 05233 discrete_distribution(_InputIterator __wbegin, 05234 _InputIterator __wend) 05235 : _M_param(__wbegin, __wend) 05236 { } 05237 05238 discrete_distribution(initializer_list<double> __wl) 05239 : _M_param(__wl) 05240 { } 05241 05242 template<typename _Func> 05243 discrete_distribution(size_t __nw, double __xmin, double __xmax, 05244 _Func __fw) 05245 : _M_param(__nw, __xmin, __xmax, __fw) 05246 { } 05247 05248 explicit 05249 discrete_distribution(const param_type& __p) 05250 : _M_param(__p) 05251 { } 05252 05253 /** 05254 * @brief Resets the distribution state. 05255 */ 05256 void 05257 reset() 05258 { } 05259 05260 /** 05261 * @brief Returns the probabilities of the distribution. 05262 */ 05263 std::vector<double> 05264 probabilities() const 05265 { 05266 return _M_param._M_prob.empty() 05267 ? std::vector<double>(1, 1.0) : _M_param._M_prob; 05268 } 05269 05270 /** 05271 * @brief Returns the parameter set of the distribution. 05272 */ 05273 param_type 05274 param() const 05275 { return _M_param; } 05276 05277 /** 05278 * @brief Sets the parameter set of the distribution. 05279 * @param __param The new parameter set of the distribution. 05280 */ 05281 void 05282 param(const param_type& __param) 05283 { _M_param = __param; } 05284 05285 /** 05286 * @brief Returns the greatest lower bound value of the distribution. 05287 */ 05288 result_type 05289 min() const 05290 { return result_type(0); } 05291 05292 /** 05293 * @brief Returns the least upper bound value of the distribution. 05294 */ 05295 result_type 05296 max() const 05297 { 05298 return _M_param._M_prob.empty() 05299 ? result_type(0) : result_type(_M_param._M_prob.size() - 1); 05300 } 05301 05302 /** 05303 * @brief Generating functions. 05304 */ 05305 template<typename _UniformRandomNumberGenerator> 05306 result_type 05307 operator()(_UniformRandomNumberGenerator& __urng) 05308 { return this->operator()(__urng, _M_param); } 05309 05310 template<typename _UniformRandomNumberGenerator> 05311 result_type 05312 operator()(_UniformRandomNumberGenerator& __urng, 05313 const param_type& __p); 05314 05315 template<typename _ForwardIterator, 05316 typename _UniformRandomNumberGenerator> 05317 void 05318 __generate(_ForwardIterator __f, _ForwardIterator __t, 05319 _UniformRandomNumberGenerator& __urng) 05320 { this->__generate(__f, __t, __urng, _M_param); } 05321 05322 template<typename _ForwardIterator, 05323 typename _UniformRandomNumberGenerator> 05324 void 05325 __generate(_ForwardIterator __f, _ForwardIterator __t, 05326 _UniformRandomNumberGenerator& __urng, 05327 const param_type& __p) 05328 { this->__generate_impl(__f, __t, __urng, __p); } 05329 05330 template<typename _UniformRandomNumberGenerator> 05331 void 05332 __generate(result_type* __f, result_type* __t, 05333 _UniformRandomNumberGenerator& __urng, 05334 const param_type& __p) 05335 { this->__generate_impl(__f, __t, __urng, __p); } 05336 05337 /** 05338 * @brief Return true if two discrete distributions have the same 05339 * parameters. 05340 */ 05341 friend bool 05342 operator==(const discrete_distribution& __d1, 05343 const discrete_distribution& __d2) 05344 { return __d1._M_param == __d2._M_param; } 05345 05346 /** 05347 * @brief Inserts a %discrete_distribution random number distribution 05348 * @p __x into the output stream @p __os. 05349 * 05350 * @param __os An output stream. 05351 * @param __x A %discrete_distribution random number distribution. 05352 * 05353 * @returns The output stream with the state of @p __x inserted or in 05354 * an error state. 05355 */ 05356 template<typename _IntType1, typename _CharT, typename _Traits> 05357 friend std::basic_ostream<_CharT, _Traits>& 05358 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 05359 const std::discrete_distribution<_IntType1>& __x); 05360 05361 /** 05362 * @brief Extracts a %discrete_distribution random number distribution 05363 * @p __x from the input stream @p __is. 05364 * 05365 * @param __is An input stream. 05366 * @param __x A %discrete_distribution random number 05367 * generator engine. 05368 * 05369 * @returns The input stream with @p __x extracted or in an error 05370 * state. 05371 */ 05372 template<typename _IntType1, typename _CharT, typename _Traits> 05373 friend std::basic_istream<_CharT, _Traits>& 05374 operator>>(std::basic_istream<_CharT, _Traits>& __is, 05375 std::discrete_distribution<_IntType1>& __x); 05376 05377 private: 05378 template<typename _ForwardIterator, 05379 typename _UniformRandomNumberGenerator> 05380 void 05381 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 05382 _UniformRandomNumberGenerator& __urng, 05383 const param_type& __p); 05384 05385 param_type _M_param; 05386 }; 05387 05388 /** 05389 * @brief Return true if two discrete distributions have different 05390 * parameters. 05391 */ 05392 template<typename _IntType> 05393 inline bool 05394 operator!=(const std::discrete_distribution<_IntType>& __d1, 05395 const std::discrete_distribution<_IntType>& __d2) 05396 { return !(__d1 == __d2); } 05397 05398 05399 /** 05400 * @brief A piecewise_constant_distribution random number distribution. 05401 * 05402 * The formula for the piecewise constant probability mass function is 05403 * 05404 */ 05405 template<typename _RealType = double> 05406 class piecewise_constant_distribution 05407 { 05408 static_assert(std::is_floating_point<_RealType>::value, 05409 "result_type must be a floating point type"); 05410 05411 public: 05412 /** The type of the range of the distribution. */ 05413 typedef _RealType result_type; 05414 05415 /** Parameter type. */ 05416 struct param_type 05417 { 05418 typedef piecewise_constant_distribution<_RealType> distribution_type; 05419 friend class piecewise_constant_distribution<_RealType>; 05420 05421 param_type() 05422 : _M_int(), _M_den(), _M_cp() 05423 { } 05424 05425 template<typename _InputIteratorB, typename _InputIteratorW> 05426 param_type(_InputIteratorB __bfirst, 05427 _InputIteratorB __bend, 05428 _InputIteratorW __wbegin); 05429 05430 template<typename _Func> 05431 param_type(initializer_list<_RealType> __bi, _Func __fw); 05432 05433 template<typename _Func> 05434 param_type(size_t __nw, _RealType __xmin, _RealType __xmax, 05435 _Func __fw); 05436 05437 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/ 05438 param_type(const param_type&) = default; 05439 param_type& operator=(const param_type&) = default; 05440 05441 std::vector<_RealType> 05442 intervals() const 05443 { 05444 if (_M_int.empty()) 05445 { 05446 std::vector<_RealType> __tmp(2); 05447 __tmp[1] = _RealType(1); 05448 return __tmp; 05449 } 05450 else 05451 return _M_int; 05452 } 05453 05454 std::vector<double> 05455 densities() const 05456 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; } 05457 05458 friend bool 05459 operator==(const param_type& __p1, const param_type& __p2) 05460 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; } 05461 05462 friend bool 05463 operator!=(const param_type& __p1, const param_type& __p2) 05464 { return !(__p1 == __p2); } 05465 05466 private: 05467 void 05468 _M_initialize(); 05469 05470 std::vector<_RealType> _M_int; 05471 std::vector<double> _M_den; 05472 std::vector<double> _M_cp; 05473 }; 05474 05475 explicit 05476 piecewise_constant_distribution() 05477 : _M_param() 05478 { } 05479 05480 template<typename _InputIteratorB, typename _InputIteratorW> 05481 piecewise_constant_distribution(_InputIteratorB __bfirst, 05482 _InputIteratorB __bend, 05483 _InputIteratorW __wbegin) 05484 : _M_param(__bfirst, __bend, __wbegin) 05485 { } 05486 05487 template<typename _Func> 05488 piecewise_constant_distribution(initializer_list<_RealType> __bl, 05489 _Func __fw) 05490 : _M_param(__bl, __fw) 05491 { } 05492 05493 template<typename _Func> 05494 piecewise_constant_distribution(size_t __nw, 05495 _RealType __xmin, _RealType __xmax, 05496 _Func __fw) 05497 : _M_param(__nw, __xmin, __xmax, __fw) 05498 { } 05499 05500 explicit 05501 piecewise_constant_distribution(const param_type& __p) 05502 : _M_param(__p) 05503 { } 05504 05505 /** 05506 * @brief Resets the distribution state. 05507 */ 05508 void 05509 reset() 05510 { } 05511 05512 /** 05513 * @brief Returns a vector of the intervals. 05514 */ 05515 std::vector<_RealType> 05516 intervals() const 05517 { 05518 if (_M_param._M_int.empty()) 05519 { 05520 std::vector<_RealType> __tmp(2); 05521 __tmp[1] = _RealType(1); 05522 return __tmp; 05523 } 05524 else 05525 return _M_param._M_int; 05526 } 05527 05528 /** 05529 * @brief Returns a vector of the probability densities. 05530 */ 05531 std::vector<double> 05532 densities() const 05533 { 05534 return _M_param._M_den.empty() 05535 ? std::vector<double>(1, 1.0) : _M_param._M_den; 05536 } 05537 05538 /** 05539 * @brief Returns the parameter set of the distribution. 05540 */ 05541 param_type 05542 param() const 05543 { return _M_param; } 05544 05545 /** 05546 * @brief Sets the parameter set of the distribution. 05547 * @param __param The new parameter set of the distribution. 05548 */ 05549 void 05550 param(const param_type& __param) 05551 { _M_param = __param; } 05552 05553 /** 05554 * @brief Returns the greatest lower bound value of the distribution. 05555 */ 05556 result_type 05557 min() const 05558 { 05559 return _M_param._M_int.empty() 05560 ? result_type(0) : _M_param._M_int.front(); 05561 } 05562 05563 /** 05564 * @brief Returns the least upper bound value of the distribution. 05565 */ 05566 result_type 05567 max() const 05568 { 05569 return _M_param._M_int.empty() 05570 ? result_type(1) : _M_param._M_int.back(); 05571 } 05572 05573 /** 05574 * @brief Generating functions. 05575 */ 05576 template<typename _UniformRandomNumberGenerator> 05577 result_type 05578 operator()(_UniformRandomNumberGenerator& __urng) 05579 { return this->operator()(__urng, _M_param); } 05580 05581 template<typename _UniformRandomNumberGenerator> 05582 result_type 05583 operator()(_UniformRandomNumberGenerator& __urng, 05584 const param_type& __p); 05585 05586 template<typename _ForwardIterator, 05587 typename _UniformRandomNumberGenerator> 05588 void 05589 __generate(_ForwardIterator __f, _ForwardIterator __t, 05590 _UniformRandomNumberGenerator& __urng) 05591 { this->__generate(__f, __t, __urng, _M_param); } 05592 05593 template<typename _ForwardIterator, 05594 typename _UniformRandomNumberGenerator> 05595 void 05596 __generate(_ForwardIterator __f, _ForwardIterator __t, 05597 _UniformRandomNumberGenerator& __urng, 05598 const param_type& __p) 05599 { this->__generate_impl(__f, __t, __urng, __p); } 05600 05601 template<typename _UniformRandomNumberGenerator> 05602 void 05603 __generate(result_type* __f, result_type* __t, 05604 _UniformRandomNumberGenerator& __urng, 05605 const param_type& __p) 05606 { this->__generate_impl(__f, __t, __urng, __p); } 05607 05608 /** 05609 * @brief Return true if two piecewise constant distributions have the 05610 * same parameters. 05611 */ 05612 friend bool 05613 operator==(const piecewise_constant_distribution& __d1, 05614 const piecewise_constant_distribution& __d2) 05615 { return __d1._M_param == __d2._M_param; } 05616 05617 /** 05618 * @brief Inserts a %piecewise_constant_distribution random 05619 * number distribution @p __x into the output stream @p __os. 05620 * 05621 * @param __os An output stream. 05622 * @param __x A %piecewise_constant_distribution random number 05623 * distribution. 05624 * 05625 * @returns The output stream with the state of @p __x inserted or in 05626 * an error state. 05627 */ 05628 template<typename _RealType1, typename _CharT, typename _Traits> 05629 friend std::basic_ostream<_CharT, _Traits>& 05630 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 05631 const std::piecewise_constant_distribution<_RealType1>& __x); 05632 05633 /** 05634 * @brief Extracts a %piecewise_constant_distribution random 05635 * number distribution @p __x from the input stream @p __is. 05636 * 05637 * @param __is An input stream. 05638 * @param __x A %piecewise_constant_distribution random number 05639 * generator engine. 05640 * 05641 * @returns The input stream with @p __x extracted or in an error 05642 * state. 05643 */ 05644 template<typename _RealType1, typename _CharT, typename _Traits> 05645 friend std::basic_istream<_CharT, _Traits>& 05646 operator>>(std::basic_istream<_CharT, _Traits>& __is, 05647 std::piecewise_constant_distribution<_RealType1>& __x); 05648 05649 private: 05650 template<typename _ForwardIterator, 05651 typename _UniformRandomNumberGenerator> 05652 void 05653 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 05654 _UniformRandomNumberGenerator& __urng, 05655 const param_type& __p); 05656 05657 param_type _M_param; 05658 }; 05659 05660 /** 05661 * @brief Return true if two piecewise constant distributions have 05662 * different parameters. 05663 */ 05664 template<typename _RealType> 05665 inline bool 05666 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1, 05667 const std::piecewise_constant_distribution<_RealType>& __d2) 05668 { return !(__d1 == __d2); } 05669 05670 05671 /** 05672 * @brief A piecewise_linear_distribution random number distribution. 05673 * 05674 * The formula for the piecewise linear probability mass function is 05675 * 05676 */ 05677 template<typename _RealType = double> 05678 class piecewise_linear_distribution 05679 { 05680 static_assert(std::is_floating_point<_RealType>::value, 05681 "result_type must be a floating point type"); 05682 05683 public: 05684 /** The type of the range of the distribution. */ 05685 typedef _RealType result_type; 05686 05687 /** Parameter type. */ 05688 struct param_type 05689 { 05690 typedef piecewise_linear_distribution<_RealType> distribution_type; 05691 friend class piecewise_linear_distribution<_RealType>; 05692 05693 param_type() 05694 : _M_int(), _M_den(), _M_cp(), _M_m() 05695 { } 05696 05697 template<typename _InputIteratorB, typename _InputIteratorW> 05698 param_type(_InputIteratorB __bfirst, 05699 _InputIteratorB __bend, 05700 _InputIteratorW __wbegin); 05701 05702 template<typename _Func> 05703 param_type(initializer_list<_RealType> __bl, _Func __fw); 05704 05705 template<typename _Func> 05706 param_type(size_t __nw, _RealType __xmin, _RealType __xmax, 05707 _Func __fw); 05708 05709 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/ 05710 param_type(const param_type&) = default; 05711 param_type& operator=(const param_type&) = default; 05712 05713 std::vector<_RealType> 05714 intervals() const 05715 { 05716 if (_M_int.empty()) 05717 { 05718 std::vector<_RealType> __tmp(2); 05719 __tmp[1] = _RealType(1); 05720 return __tmp; 05721 } 05722 else 05723 return _M_int; 05724 } 05725 05726 std::vector<double> 05727 densities() const 05728 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; } 05729 05730 friend bool 05731 operator==(const param_type& __p1, const param_type& __p2) 05732 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; } 05733 05734 friend bool 05735 operator!=(const param_type& __p1, const param_type& __p2) 05736 { return !(__p1 == __p2); } 05737 05738 private: 05739 void 05740 _M_initialize(); 05741 05742 std::vector<_RealType> _M_int; 05743 std::vector<double> _M_den; 05744 std::vector<double> _M_cp; 05745 std::vector<double> _M_m; 05746 }; 05747 05748 explicit 05749 piecewise_linear_distribution() 05750 : _M_param() 05751 { } 05752 05753 template<typename _InputIteratorB, typename _InputIteratorW> 05754 piecewise_linear_distribution(_InputIteratorB __bfirst, 05755 _InputIteratorB __bend, 05756 _InputIteratorW __wbegin) 05757 : _M_param(__bfirst, __bend, __wbegin) 05758 { } 05759 05760 template<typename _Func> 05761 piecewise_linear_distribution(initializer_list<_RealType> __bl, 05762 _Func __fw) 05763 : _M_param(__bl, __fw) 05764 { } 05765 05766 template<typename _Func> 05767 piecewise_linear_distribution(size_t __nw, 05768 _RealType __xmin, _RealType __xmax, 05769 _Func __fw) 05770 : _M_param(__nw, __xmin, __xmax, __fw) 05771 { } 05772 05773 explicit 05774 piecewise_linear_distribution(const param_type& __p) 05775 : _M_param(__p) 05776 { } 05777 05778 /** 05779 * Resets the distribution state. 05780 */ 05781 void 05782 reset() 05783 { } 05784 05785 /** 05786 * @brief Return the intervals of the distribution. 05787 */ 05788 std::vector<_RealType> 05789 intervals() const 05790 { 05791 if (_M_param._M_int.empty()) 05792 { 05793 std::vector<_RealType> __tmp(2); 05794 __tmp[1] = _RealType(1); 05795 return __tmp; 05796 } 05797 else 05798 return _M_param._M_int; 05799 } 05800 05801 /** 05802 * @brief Return a vector of the probability densities of the 05803 * distribution. 05804 */ 05805 std::vector<double> 05806 densities() const 05807 { 05808 return _M_param._M_den.empty() 05809 ? std::vector<double>(2, 1.0) : _M_param._M_den; 05810 } 05811 05812 /** 05813 * @brief Returns the parameter set of the distribution. 05814 */ 05815 param_type 05816 param() const 05817 { return _M_param; } 05818 05819 /** 05820 * @brief Sets the parameter set of the distribution. 05821 * @param __param The new parameter set of the distribution. 05822 */ 05823 void 05824 param(const param_type& __param) 05825 { _M_param = __param; } 05826 05827 /** 05828 * @brief Returns the greatest lower bound value of the distribution. 05829 */ 05830 result_type 05831 min() const 05832 { 05833 return _M_param._M_int.empty() 05834 ? result_type(0) : _M_param._M_int.front(); 05835 } 05836 05837 /** 05838 * @brief Returns the least upper bound value of the distribution. 05839 */ 05840 result_type 05841 max() const 05842 { 05843 return _M_param._M_int.empty() 05844 ? result_type(1) : _M_param._M_int.back(); 05845 } 05846 05847 /** 05848 * @brief Generating functions. 05849 */ 05850 template<typename _UniformRandomNumberGenerator> 05851 result_type 05852 operator()(_UniformRandomNumberGenerator& __urng) 05853 { return this->operator()(__urng, _M_param); } 05854 05855 template<typename _UniformRandomNumberGenerator> 05856 result_type 05857 operator()(_UniformRandomNumberGenerator& __urng, 05858 const param_type& __p); 05859 05860 template<typename _ForwardIterator, 05861 typename _UniformRandomNumberGenerator> 05862 void 05863 __generate(_ForwardIterator __f, _ForwardIterator __t, 05864 _UniformRandomNumberGenerator& __urng) 05865 { this->__generate(__f, __t, __urng, _M_param); } 05866 05867 template<typename _ForwardIterator, 05868 typename _UniformRandomNumberGenerator> 05869 void 05870 __generate(_ForwardIterator __f, _ForwardIterator __t, 05871 _UniformRandomNumberGenerator& __urng, 05872 const param_type& __p) 05873 { this->__generate_impl(__f, __t, __urng, __p); } 05874 05875 template<typename _UniformRandomNumberGenerator> 05876 void 05877 __generate(result_type* __f, result_type* __t, 05878 _UniformRandomNumberGenerator& __urng, 05879 const param_type& __p) 05880 { this->__generate_impl(__f, __t, __urng, __p); } 05881 05882 /** 05883 * @brief Return true if two piecewise linear distributions have the 05884 * same parameters. 05885 */ 05886 friend bool 05887 operator==(const piecewise_linear_distribution& __d1, 05888 const piecewise_linear_distribution& __d2) 05889 { return __d1._M_param == __d2._M_param; } 05890 05891 /** 05892 * @brief Inserts a %piecewise_linear_distribution random number 05893 * distribution @p __x into the output stream @p __os. 05894 * 05895 * @param __os An output stream. 05896 * @param __x A %piecewise_linear_distribution random number 05897 * distribution. 05898 * 05899 * @returns The output stream with the state of @p __x inserted or in 05900 * an error state. 05901 */ 05902 template<typename _RealType1, typename _CharT, typename _Traits> 05903 friend std::basic_ostream<_CharT, _Traits>& 05904 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 05905 const std::piecewise_linear_distribution<_RealType1>& __x); 05906 05907 /** 05908 * @brief Extracts a %piecewise_linear_distribution random number 05909 * distribution @p __x from the input stream @p __is. 05910 * 05911 * @param __is An input stream. 05912 * @param __x A %piecewise_linear_distribution random number 05913 * generator engine. 05914 * 05915 * @returns The input stream with @p __x extracted or in an error 05916 * state. 05917 */ 05918 template<typename _RealType1, typename _CharT, typename _Traits> 05919 friend std::basic_istream<_CharT, _Traits>& 05920 operator>>(std::basic_istream<_CharT, _Traits>& __is, 05921 std::piecewise_linear_distribution<_RealType1>& __x); 05922 05923 private: 05924 template<typename _ForwardIterator, 05925 typename _UniformRandomNumberGenerator> 05926 void 05927 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 05928 _UniformRandomNumberGenerator& __urng, 05929 const param_type& __p); 05930 05931 param_type _M_param; 05932 }; 05933 05934 /** 05935 * @brief Return true if two piecewise linear distributions have 05936 * different parameters. 05937 */ 05938 template<typename _RealType> 05939 inline bool 05940 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1, 05941 const std::piecewise_linear_distribution<_RealType>& __d2) 05942 { return !(__d1 == __d2); } 05943 05944 05945 /* @} */ // group random_distributions_poisson 05946 05947 /* @} */ // group random_distributions 05948 05949 /** 05950 * @addtogroup random_utilities Random Number Utilities 05951 * @ingroup random 05952 * @{ 05953 */ 05954 05955 /** 05956 * @brief The seed_seq class generates sequences of seeds for random 05957 * number generators. 05958 */ 05959 class seed_seq 05960 { 05961 public: 05962 /** The type of the seed vales. */ 05963 typedef uint_least32_t result_type; 05964 05965 /** Default constructor. */ 05966 seed_seq() noexcept 05967 : _M_v() 05968 { } 05969 05970 template<typename _IntType> 05971 seed_seq(std::initializer_list<_IntType> il); 05972 05973 template<typename _InputIterator> 05974 seed_seq(_InputIterator __begin, _InputIterator __end); 05975 05976 // generating functions 05977 template<typename _RandomAccessIterator> 05978 void 05979 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end); 05980 05981 // property functions 05982 size_t size() const noexcept 05983 { return _M_v.size(); } 05984 05985 template<typename OutputIterator> 05986 void 05987 param(OutputIterator __dest) const 05988 { std::copy(_M_v.begin(), _M_v.end(), __dest); } 05989 05990 // no copy functions 05991 seed_seq(const seed_seq&) = delete; 05992 seed_seq& operator=(const seed_seq&) = delete; 05993 05994 private: 05995 std::vector<result_type> _M_v; 05996 }; 05997 05998 /* @} */ // group random_utilities 05999 06000 /* @} */ // group random 06001 06002 _GLIBCXX_END_NAMESPACE_VERSION 06003 } // namespace std 06004 06005 #endif