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