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