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