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