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, _IntType __t);
03982 
03983       param_type _M_param;
03984 
03985       // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
03986       std::normal_distribution<double> _M_nd;
03987     };
03988 
03989   /**
03990    * @brief Return true if two binomial distributions are different.
03991    */
03992   template<typename _IntType>
03993     inline bool
03994     operator!=(const std::binomial_distribution<_IntType>& __d1,
03995            const std::binomial_distribution<_IntType>& __d2)
03996     { return !(__d1 == __d2); }
03997 
03998 
03999   /**
04000    * @brief A discrete geometric random number distribution.
04001    *
04002    * The formula for the geometric probability density function is
04003    * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
04004    * distribution.
04005    */
04006   template<typename _IntType = int>
04007     class geometric_distribution
04008     {
04009       static_assert(std::is_integral<_IntType>::value,
04010             "template argument not an integral type");
04011 
04012     public:
04013       /** The type of the range of the distribution. */
04014       typedef _IntType  result_type;
04015       /** Parameter type. */
04016       struct param_type
04017       {
04018     typedef geometric_distribution<_IntType> distribution_type;
04019     friend class geometric_distribution<_IntType>;
04020 
04021     explicit
04022     param_type(double __p = 0.5)
04023     : _M_p(__p)
04024     {
04025       _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
04026       _M_initialize();
04027     }
04028 
04029     double
04030     p() const
04031     { return _M_p; }
04032 
04033     friend bool
04034     operator==(const param_type& __p1, const param_type& __p2)
04035     { return __p1._M_p == __p2._M_p; }
04036 
04037       private:
04038     void
04039     _M_initialize()
04040     { _M_log_1_p = std::log(1.0 - _M_p); }
04041 
04042     double _M_p;
04043 
04044     double _M_log_1_p;
04045       };
04046 
04047       // constructors and member function
04048       explicit
04049       geometric_distribution(double __p = 0.5)
04050       : _M_param(__p)
04051       { }
04052 
04053       explicit
04054       geometric_distribution(const param_type& __p)
04055       : _M_param(__p)
04056       { }
04057 
04058       /**
04059        * @brief Resets the distribution state.
04060        *
04061        * Does nothing for the geometric distribution.
04062        */
04063       void
04064       reset() { }
04065 
04066       /**
04067        * @brief Returns the distribution parameter @p p.
04068        */
04069       double
04070       p() const
04071       { return _M_param.p(); }
04072 
04073       /**
04074        * @brief Returns the parameter set of the distribution.
04075        */
04076       param_type
04077       param() const
04078       { return _M_param; }
04079 
04080       /**
04081        * @brief Sets the parameter set of the distribution.
04082        * @param __param The new parameter set of the distribution.
04083        */
04084       void
04085       param(const param_type& __param)
04086       { _M_param = __param; }
04087 
04088       /**
04089        * @brief Returns the greatest lower bound value of the distribution.
04090        */
04091       result_type
04092       min() const
04093       { return 0; }
04094 
04095       /**
04096        * @brief Returns the least upper bound value of the distribution.
04097        */
04098       result_type
04099       max() const
04100       { return std::numeric_limits<result_type>::max(); }
04101 
04102       /**
04103        * @brief Generating functions.
04104        */
04105       template<typename _UniformRandomNumberGenerator>
04106     result_type
04107     operator()(_UniformRandomNumberGenerator& __urng)
04108     { return this->operator()(__urng, _M_param); }
04109 
04110       template<typename _UniformRandomNumberGenerator>
04111     result_type
04112     operator()(_UniformRandomNumberGenerator& __urng,
04113            const param_type& __p);
04114 
04115       template<typename _ForwardIterator,
04116            typename _UniformRandomNumberGenerator>
04117     void
04118     __generate(_ForwardIterator __f, _ForwardIterator __t,
04119            _UniformRandomNumberGenerator& __urng)
04120     { this->__generate(__f, __t, __urng, _M_param); }
04121 
04122       template<typename _ForwardIterator,
04123            typename _UniformRandomNumberGenerator>
04124     void
04125     __generate(_ForwardIterator __f, _ForwardIterator __t,
04126            _UniformRandomNumberGenerator& __urng,
04127            const param_type& __p)
04128     { this->__generate_impl(__f, __t, __urng, __p); }
04129 
04130       template<typename _UniformRandomNumberGenerator>
04131     void
04132     __generate(result_type* __f, result_type* __t,
04133            _UniformRandomNumberGenerator& __urng,
04134            const param_type& __p)
04135     { this->__generate_impl(__f, __t, __urng, __p); }
04136 
04137       /**
04138        * @brief Return true if two geometric distributions have
04139        *        the same parameters.
04140        */
04141       friend bool
04142       operator==(const geometric_distribution& __d1,
04143          const geometric_distribution& __d2)
04144       { return __d1._M_param == __d2._M_param; }
04145 
04146     private:
04147       template<typename _ForwardIterator,
04148            typename _UniformRandomNumberGenerator>
04149     void
04150     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04151             _UniformRandomNumberGenerator& __urng,
04152             const param_type& __p);
04153 
04154       param_type _M_param;
04155     };
04156 
04157   /**
04158    * @brief Return true if two geometric distributions have
04159    *        different parameters.
04160    */
04161   template<typename _IntType>
04162     inline bool
04163     operator!=(const std::geometric_distribution<_IntType>& __d1,
04164            const std::geometric_distribution<_IntType>& __d2)
04165     { return !(__d1 == __d2); }
04166 
04167   /**
04168    * @brief Inserts a %geometric_distribution random number distribution
04169    * @p __x into the output stream @p __os.
04170    *
04171    * @param __os An output stream.
04172    * @param __x  A %geometric_distribution random number distribution.
04173    *
04174    * @returns The output stream with the state of @p __x inserted or in
04175    * an error state.
04176    */
04177   template<typename _IntType,
04178        typename _CharT, typename _Traits>
04179     std::basic_ostream<_CharT, _Traits>&
04180     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04181            const std::geometric_distribution<_IntType>& __x);
04182 
04183   /**
04184    * @brief Extracts a %geometric_distribution random number distribution
04185    * @p __x from the input stream @p __is.
04186    *
04187    * @param __is An input stream.
04188    * @param __x  A %geometric_distribution random number generator engine.
04189    *
04190    * @returns The input stream with @p __x extracted or in an error state.
04191    */
04192   template<typename _IntType,
04193        typename _CharT, typename _Traits>
04194     std::basic_istream<_CharT, _Traits>&
04195     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04196            std::geometric_distribution<_IntType>& __x);
04197 
04198 
04199   /**
04200    * @brief A negative_binomial_distribution random number distribution.
04201    *
04202    * The formula for the negative binomial probability mass function is
04203    * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
04204    * and @f$p@f$ are the parameters of the distribution.
04205    */
04206   template<typename _IntType = int>
04207     class negative_binomial_distribution
04208     {
04209       static_assert(std::is_integral<_IntType>::value,
04210             "template argument not an integral type");
04211 
04212     public:
04213       /** The type of the range of the distribution. */
04214       typedef _IntType result_type;
04215       /** Parameter type. */
04216       struct param_type
04217       {
04218     typedef negative_binomial_distribution<_IntType> distribution_type;
04219 
04220     explicit
04221     param_type(_IntType __k = 1, double __p = 0.5)
04222     : _M_k(__k), _M_p(__p)
04223     {
04224       _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
04225     }
04226 
04227     _IntType
04228     k() const
04229     { return _M_k; }
04230 
04231     double
04232     p() const
04233     { return _M_p; }
04234 
04235     friend bool
04236     operator==(const param_type& __p1, const param_type& __p2)
04237     { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
04238 
04239       private:
04240     _IntType _M_k;
04241     double _M_p;
04242       };
04243 
04244       explicit
04245       negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
04246       : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
04247       { }
04248 
04249       explicit
04250       negative_binomial_distribution(const param_type& __p)
04251       : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
04252       { }
04253 
04254       /**
04255        * @brief Resets the distribution state.
04256        */
04257       void
04258       reset()
04259       { _M_gd.reset(); }
04260 
04261       /**
04262        * @brief Return the @f$k@f$ parameter of the distribution.
04263        */
04264       _IntType
04265       k() const
04266       { return _M_param.k(); }
04267 
04268       /**
04269        * @brief Return the @f$p@f$ parameter of the distribution.
04270        */
04271       double
04272       p() const
04273       { return _M_param.p(); }
04274 
04275       /**
04276        * @brief Returns the parameter set of the distribution.
04277        */
04278       param_type
04279       param() const
04280       { return _M_param; }
04281 
04282       /**
04283        * @brief Sets the parameter set of the distribution.
04284        * @param __param The new parameter set of the distribution.
04285        */
04286       void
04287       param(const param_type& __param)
04288       { _M_param = __param; }
04289 
04290       /**
04291        * @brief Returns the greatest lower bound value of the distribution.
04292        */
04293       result_type
04294       min() const
04295       { return result_type(0); }
04296 
04297       /**
04298        * @brief Returns the least upper bound value of the distribution.
04299        */
04300       result_type
04301       max() const
04302       { return std::numeric_limits<result_type>::max(); }
04303 
04304       /**
04305        * @brief Generating functions.
04306        */
04307       template<typename _UniformRandomNumberGenerator>
04308     result_type
04309         operator()(_UniformRandomNumberGenerator& __urng);
04310 
04311       template<typename _UniformRandomNumberGenerator>
04312     result_type
04313     operator()(_UniformRandomNumberGenerator& __urng,
04314            const param_type& __p);
04315 
04316       template<typename _ForwardIterator,
04317            typename _UniformRandomNumberGenerator>
04318     void
04319     __generate(_ForwardIterator __f, _ForwardIterator __t,
04320            _UniformRandomNumberGenerator& __urng)
04321     { this->__generate_impl(__f, __t, __urng); }
04322 
04323       template<typename _ForwardIterator,
04324            typename _UniformRandomNumberGenerator>
04325     void
04326     __generate(_ForwardIterator __f, _ForwardIterator __t,
04327            _UniformRandomNumberGenerator& __urng,
04328            const param_type& __p)
04329     { this->__generate_impl(__f, __t, __urng, __p); }
04330 
04331       template<typename _UniformRandomNumberGenerator>
04332     void
04333     __generate(result_type* __f, result_type* __t,
04334            _UniformRandomNumberGenerator& __urng)
04335     { this->__generate_impl(__f, __t, __urng); }
04336 
04337       template<typename _UniformRandomNumberGenerator>
04338     void
04339     __generate(result_type* __f, result_type* __t,
04340            _UniformRandomNumberGenerator& __urng,
04341            const param_type& __p)
04342     { this->__generate_impl(__f, __t, __urng, __p); }
04343 
04344       /**
04345        * @brief Return true if two negative binomial distributions have
04346        *        the same parameters and the sequences that would be
04347        *        generated are equal.
04348        */
04349       friend bool
04350       operator==(const negative_binomial_distribution& __d1,
04351          const negative_binomial_distribution& __d2)
04352       { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
04353 
04354       /**
04355        * @brief Inserts a %negative_binomial_distribution random
04356        *        number distribution @p __x into the output stream @p __os.
04357        *
04358        * @param __os An output stream.
04359        * @param __x  A %negative_binomial_distribution random number
04360        *             distribution.
04361        *
04362        * @returns The output stream with the state of @p __x inserted or in
04363        *          an error state.
04364        */
04365       template<typename _IntType1, typename _CharT, typename _Traits>
04366     friend std::basic_ostream<_CharT, _Traits>&
04367     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04368            const std::negative_binomial_distribution<_IntType1>& __x);
04369 
04370       /**
04371        * @brief Extracts a %negative_binomial_distribution random number
04372        *        distribution @p __x from the input stream @p __is.
04373        *
04374        * @param __is An input stream.
04375        * @param __x A %negative_binomial_distribution random number
04376        *            generator engine.
04377        *
04378        * @returns The input stream with @p __x extracted or in an error state.
04379        */
04380       template<typename _IntType1, typename _CharT, typename _Traits>
04381     friend std::basic_istream<_CharT, _Traits>&
04382     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04383            std::negative_binomial_distribution<_IntType1>& __x);
04384 
04385     private:
04386       template<typename _ForwardIterator,
04387            typename _UniformRandomNumberGenerator>
04388     void
04389     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04390             _UniformRandomNumberGenerator& __urng);
04391       template<typename _ForwardIterator,
04392            typename _UniformRandomNumberGenerator>
04393     void
04394     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04395             _UniformRandomNumberGenerator& __urng,
04396             const param_type& __p);
04397 
04398       param_type _M_param;
04399 
04400       std::gamma_distribution<double> _M_gd;
04401     };
04402 
04403   /**
04404    * @brief Return true if two negative binomial distributions are different.
04405    */
04406   template<typename _IntType>
04407     inline bool
04408     operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
04409            const std::negative_binomial_distribution<_IntType>& __d2)
04410     { return !(__d1 == __d2); }
04411 
04412 
04413   /* @} */ // group random_distributions_bernoulli
04414 
04415   /**
04416    * @addtogroup random_distributions_poisson Poisson Distributions
04417    * @ingroup random_distributions
04418    * @{
04419    */
04420 
04421   /**
04422    * @brief A discrete Poisson random number distribution.
04423    *
04424    * The formula for the Poisson probability density function is
04425    * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
04426    * parameter of the distribution.
04427    */
04428   template<typename _IntType = int>
04429     class poisson_distribution
04430     {
04431       static_assert(std::is_integral<_IntType>::value,
04432             "template argument not an integral type");
04433 
04434     public:
04435       /** The type of the range of the distribution. */
04436       typedef _IntType  result_type;
04437       /** Parameter type. */
04438       struct param_type
04439       {
04440     typedef poisson_distribution<_IntType> distribution_type;
04441     friend class poisson_distribution<_IntType>;
04442 
04443     explicit
04444     param_type(double __mean = 1.0)
04445     : _M_mean(__mean)
04446     {
04447       _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
04448       _M_initialize();
04449     }
04450 
04451     double
04452     mean() const
04453     { return _M_mean; }
04454 
04455     friend bool
04456     operator==(const param_type& __p1, const param_type& __p2)
04457     { return __p1._M_mean == __p2._M_mean; }
04458 
04459       private:
04460     // Hosts either log(mean) or the threshold of the simple method.
04461     void
04462     _M_initialize();
04463 
04464     double _M_mean;
04465 
04466     double _M_lm_thr;
04467 #if _GLIBCXX_USE_C99_MATH_TR1
04468     double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
04469 #endif
04470       };
04471 
04472       // constructors and member function
04473       explicit
04474       poisson_distribution(double __mean = 1.0)
04475       : _M_param(__mean), _M_nd()
04476       { }
04477 
04478       explicit
04479       poisson_distribution(const param_type& __p)
04480       : _M_param(__p), _M_nd()
04481       { }
04482 
04483       /**
04484        * @brief Resets the distribution state.
04485        */
04486       void
04487       reset()
04488       { _M_nd.reset(); }
04489 
04490       /**
04491        * @brief Returns the distribution parameter @p mean.
04492        */
04493       double
04494       mean() const
04495       { return _M_param.mean(); }
04496 
04497       /**
04498        * @brief Returns the parameter set of the distribution.
04499        */
04500       param_type
04501       param() const
04502       { return _M_param; }
04503 
04504       /**
04505        * @brief Sets the parameter set of the distribution.
04506        * @param __param The new parameter set of the distribution.
04507        */
04508       void
04509       param(const param_type& __param)
04510       { _M_param = __param; }
04511 
04512       /**
04513        * @brief Returns the greatest lower bound value of the distribution.
04514        */
04515       result_type
04516       min() const
04517       { return 0; }
04518 
04519       /**
04520        * @brief Returns the least upper bound value of the distribution.
04521        */
04522       result_type
04523       max() const
04524       { return std::numeric_limits<result_type>::max(); }
04525 
04526       /**
04527        * @brief Generating functions.
04528        */
04529       template<typename _UniformRandomNumberGenerator>
04530     result_type
04531     operator()(_UniformRandomNumberGenerator& __urng)
04532     { return this->operator()(__urng, _M_param); }
04533 
04534       template<typename _UniformRandomNumberGenerator>
04535     result_type
04536     operator()(_UniformRandomNumberGenerator& __urng,
04537            const param_type& __p);
04538 
04539       template<typename _ForwardIterator,
04540            typename _UniformRandomNumberGenerator>
04541     void
04542     __generate(_ForwardIterator __f, _ForwardIterator __t,
04543            _UniformRandomNumberGenerator& __urng)
04544     { this->__generate(__f, __t, __urng, _M_param); }
04545 
04546       template<typename _ForwardIterator,
04547            typename _UniformRandomNumberGenerator>
04548     void
04549     __generate(_ForwardIterator __f, _ForwardIterator __t,
04550            _UniformRandomNumberGenerator& __urng,
04551            const param_type& __p)
04552     { this->__generate_impl(__f, __t, __urng, __p); }
04553 
04554       template<typename _UniformRandomNumberGenerator>
04555     void
04556     __generate(result_type* __f, result_type* __t,
04557            _UniformRandomNumberGenerator& __urng,
04558            const param_type& __p)
04559     { this->__generate_impl(__f, __t, __urng, __p); }
04560 
04561        /**
04562     * @brief Return true if two Poisson distributions have the same
04563     *        parameters and the sequences that would be generated
04564     *        are equal.
04565     */
04566       friend bool
04567       operator==(const poisson_distribution& __d1,
04568          const poisson_distribution& __d2)
04569 #ifdef _GLIBCXX_USE_C99_MATH_TR1
04570       { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
04571 #else
04572       { return __d1._M_param == __d2._M_param; }
04573 #endif
04574 
04575       /**
04576        * @brief Inserts a %poisson_distribution random number distribution
04577        * @p __x into the output stream @p __os.
04578        *
04579        * @param __os An output stream.
04580        * @param __x  A %poisson_distribution random number distribution.
04581        *
04582        * @returns The output stream with the state of @p __x inserted or in
04583        * an error state.
04584        */
04585       template<typename _IntType1, typename _CharT, typename _Traits>
04586     friend std::basic_ostream<_CharT, _Traits>&
04587     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04588            const std::poisson_distribution<_IntType1>& __x);
04589 
04590       /**
04591        * @brief Extracts a %poisson_distribution random number distribution
04592        * @p __x from the input stream @p __is.
04593        *
04594        * @param __is An input stream.
04595        * @param __x  A %poisson_distribution random number generator engine.
04596        *
04597        * @returns The input stream with @p __x extracted or in an error
04598        *          state.
04599        */
04600       template<typename _IntType1, typename _CharT, typename _Traits>
04601     friend std::basic_istream<_CharT, _Traits>&
04602     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04603            std::poisson_distribution<_IntType1>& __x);
04604 
04605     private:
04606       template<typename _ForwardIterator,
04607            typename _UniformRandomNumberGenerator>
04608     void
04609     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04610             _UniformRandomNumberGenerator& __urng,
04611             const param_type& __p);
04612 
04613       param_type _M_param;
04614 
04615       // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
04616       std::normal_distribution<double> _M_nd;
04617     };
04618 
04619   /**
04620    * @brief Return true if two Poisson distributions are different.
04621    */
04622   template<typename _IntType>
04623     inline bool
04624     operator!=(const std::poisson_distribution<_IntType>& __d1,
04625            const std::poisson_distribution<_IntType>& __d2)
04626     { return !(__d1 == __d2); }
04627 
04628 
04629   /**
04630    * @brief An exponential continuous distribution for random numbers.
04631    *
04632    * The formula for the exponential probability density function is
04633    * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
04634    *
04635    * <table border=1 cellpadding=10 cellspacing=0>
04636    * <caption align=top>Distribution Statistics</caption>
04637    * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
04638    * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
04639    * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
04640    * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
04641    * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
04642    * </table>
04643    */
04644   template<typename _RealType = double>
04645     class exponential_distribution
04646     {
04647       static_assert(std::is_floating_point<_RealType>::value,
04648             "template argument not a floating point type");
04649 
04650     public:
04651       /** The type of the range of the distribution. */
04652       typedef _RealType result_type;
04653       /** Parameter type. */
04654       struct param_type
04655       {
04656     typedef exponential_distribution<_RealType> distribution_type;
04657 
04658     explicit
04659     param_type(_RealType __lambda = _RealType(1))
04660     : _M_lambda(__lambda)
04661     {
04662       _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
04663     }
04664 
04665     _RealType
04666     lambda() const
04667     { return _M_lambda; }
04668 
04669     friend bool
04670     operator==(const param_type& __p1, const param_type& __p2)
04671     { return __p1._M_lambda == __p2._M_lambda; }
04672 
04673       private:
04674     _RealType _M_lambda;
04675       };
04676 
04677     public:
04678       /**
04679        * @brief Constructs an exponential distribution with inverse scale
04680        *        parameter @f$\lambda@f$.
04681        */
04682       explicit
04683       exponential_distribution(const result_type& __lambda = result_type(1))
04684       : _M_param(__lambda)
04685       { }
04686 
04687       explicit
04688       exponential_distribution(const param_type& __p)
04689       : _M_param(__p)
04690       { }
04691 
04692       /**
04693        * @brief Resets the distribution state.
04694        *
04695        * Has no effect on exponential distributions.
04696        */
04697       void
04698       reset() { }
04699 
04700       /**
04701        * @brief Returns the inverse scale parameter of the distribution.
04702        */
04703       _RealType
04704       lambda() const
04705       { return _M_param.lambda(); }
04706 
04707       /**
04708        * @brief Returns the parameter set of the distribution.
04709        */
04710       param_type
04711       param() const
04712       { return _M_param; }
04713 
04714       /**
04715        * @brief Sets the parameter set of the distribution.
04716        * @param __param The new parameter set of the distribution.
04717        */
04718       void
04719       param(const param_type& __param)
04720       { _M_param = __param; }
04721 
04722       /**
04723        * @brief Returns the greatest lower bound value of the distribution.
04724        */
04725       result_type
04726       min() const
04727       { return result_type(0); }
04728 
04729       /**
04730        * @brief Returns the least upper bound value of the distribution.
04731        */
04732       result_type
04733       max() const
04734       { return std::numeric_limits<result_type>::max(); }
04735 
04736       /**
04737        * @brief Generating functions.
04738        */
04739       template<typename _UniformRandomNumberGenerator>
04740     result_type
04741     operator()(_UniformRandomNumberGenerator& __urng)
04742         { return this->operator()(__urng, _M_param); }
04743 
04744       template<typename _UniformRandomNumberGenerator>
04745     result_type
04746     operator()(_UniformRandomNumberGenerator& __urng,
04747            const param_type& __p)
04748     {
04749       __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
04750         __aurng(__urng);
04751       return -std::log(result_type(1) - __aurng()) / __p.lambda();
04752     }
04753 
04754       template<typename _ForwardIterator,
04755            typename _UniformRandomNumberGenerator>
04756     void
04757     __generate(_ForwardIterator __f, _ForwardIterator __t,
04758            _UniformRandomNumberGenerator& __urng)
04759     { this->__generate(__f, __t, __urng, _M_param); }
04760 
04761       template<typename _ForwardIterator,
04762            typename _UniformRandomNumberGenerator>
04763     void
04764     __generate(_ForwardIterator __f, _ForwardIterator __t,
04765            _UniformRandomNumberGenerator& __urng,
04766            const param_type& __p)
04767     { this->__generate_impl(__f, __t, __urng, __p); }
04768 
04769       template<typename _UniformRandomNumberGenerator>
04770     void
04771     __generate(result_type* __f, result_type* __t,
04772            _UniformRandomNumberGenerator& __urng,
04773            const param_type& __p)
04774     { this->__generate_impl(__f, __t, __urng, __p); }
04775 
04776       /**
04777        * @brief Return true if two exponential distributions have the same
04778        *        parameters.
04779        */
04780       friend bool
04781       operator==(const exponential_distribution& __d1,
04782          const exponential_distribution& __d2)
04783       { return __d1._M_param == __d2._M_param; }
04784 
04785     private:
04786       template<typename _ForwardIterator,
04787            typename _UniformRandomNumberGenerator>
04788     void
04789     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04790             _UniformRandomNumberGenerator& __urng,
04791             const param_type& __p);
04792 
04793       param_type _M_param;
04794     };
04795 
04796   /**
04797    * @brief Return true if two exponential distributions have different
04798    *        parameters.
04799    */
04800   template<typename _RealType>
04801     inline bool
04802     operator!=(const std::exponential_distribution<_RealType>& __d1,
04803            const std::exponential_distribution<_RealType>& __d2)
04804     { return !(__d1 == __d2); }
04805 
04806   /**
04807    * @brief Inserts a %exponential_distribution random number distribution
04808    * @p __x into the output stream @p __os.
04809    *
04810    * @param __os An output stream.
04811    * @param __x  A %exponential_distribution random number distribution.
04812    *
04813    * @returns The output stream with the state of @p __x inserted or in
04814    * an error state.
04815    */
04816   template<typename _RealType, typename _CharT, typename _Traits>
04817     std::basic_ostream<_CharT, _Traits>&
04818     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04819            const std::exponential_distribution<_RealType>& __x);
04820 
04821   /**
04822    * @brief Extracts a %exponential_distribution random number distribution
04823    * @p __x from the input stream @p __is.
04824    *
04825    * @param __is An input stream.
04826    * @param __x A %exponential_distribution random number
04827    *            generator engine.
04828    *
04829    * @returns The input stream with @p __x extracted or in an error state.
04830    */
04831   template<typename _RealType, typename _CharT, typename _Traits>
04832     std::basic_istream<_CharT, _Traits>&
04833     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04834            std::exponential_distribution<_RealType>& __x);
04835 
04836 
04837   /**
04838    * @brief A weibull_distribution random number distribution.
04839    *
04840    * The formula for the normal probability density function is:
04841    * @f[
04842    *     p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
04843    *                         \exp{(-(\frac{x}{\beta})^\alpha)} 
04844    * @f]
04845    */
04846   template<typename _RealType = double>
04847     class weibull_distribution
04848     {
04849       static_assert(std::is_floating_point<_RealType>::value,
04850             "template argument not a floating point type");
04851 
04852     public:
04853       /** The type of the range of the distribution. */
04854       typedef _RealType result_type;
04855       /** Parameter type. */
04856       struct param_type
04857       {
04858     typedef weibull_distribution<_RealType> distribution_type;
04859 
04860     explicit
04861     param_type(_RealType __a = _RealType(1),
04862            _RealType __b = _RealType(1))
04863     : _M_a(__a), _M_b(__b)
04864     { }
04865 
04866     _RealType
04867     a() const
04868     { return _M_a; }
04869 
04870     _RealType
04871     b() const
04872     { return _M_b; }
04873 
04874     friend bool
04875     operator==(const param_type& __p1, const param_type& __p2)
04876     { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
04877 
04878       private:
04879     _RealType _M_a;
04880     _RealType _M_b;
04881       };
04882 
04883       explicit
04884       weibull_distribution(_RealType __a = _RealType(1),
04885                _RealType __b = _RealType(1))
04886       : _M_param(__a, __b)
04887       { }
04888 
04889       explicit
04890       weibull_distribution(const param_type& __p)
04891       : _M_param(__p)
04892       { }
04893 
04894       /**
04895        * @brief Resets the distribution state.
04896        */
04897       void
04898       reset()
04899       { }
04900 
04901       /**
04902        * @brief Return the @f$a@f$ parameter of the distribution.
04903        */
04904       _RealType
04905       a() const
04906       { return _M_param.a(); }
04907 
04908       /**
04909        * @brief Return the @f$b@f$ parameter of the distribution.
04910        */
04911       _RealType
04912       b() const
04913       { return _M_param.b(); }
04914 
04915       /**
04916        * @brief Returns the parameter set of the distribution.
04917        */
04918       param_type
04919       param() const
04920       { return _M_param; }
04921 
04922       /**
04923        * @brief Sets the parameter set of the distribution.
04924        * @param __param The new parameter set of the distribution.
04925        */
04926       void
04927       param(const param_type& __param)
04928       { _M_param = __param; }
04929 
04930       /**
04931        * @brief Returns the greatest lower bound value of the distribution.
04932        */
04933       result_type
04934       min() const
04935       { return result_type(0); }
04936 
04937       /**
04938        * @brief Returns the least upper bound value of the distribution.
04939        */
04940       result_type
04941       max() const
04942       { return std::numeric_limits<result_type>::max(); }
04943 
04944       /**
04945        * @brief Generating functions.
04946        */
04947       template<typename _UniformRandomNumberGenerator>
04948     result_type
04949     operator()(_UniformRandomNumberGenerator& __urng)
04950     { return this->operator()(__urng, _M_param); }
04951 
04952       template<typename _UniformRandomNumberGenerator>
04953     result_type
04954     operator()(_UniformRandomNumberGenerator& __urng,
04955            const param_type& __p);
04956 
04957       template<typename _ForwardIterator,
04958            typename _UniformRandomNumberGenerator>
04959     void
04960     __generate(_ForwardIterator __f, _ForwardIterator __t,
04961            _UniformRandomNumberGenerator& __urng)
04962     { this->__generate(__f, __t, __urng, _M_param); }
04963 
04964       template<typename _ForwardIterator,
04965            typename _UniformRandomNumberGenerator>
04966     void
04967     __generate(_ForwardIterator __f, _ForwardIterator __t,
04968            _UniformRandomNumberGenerator& __urng,
04969            const param_type& __p)
04970     { this->__generate_impl(__f, __t, __urng, __p); }
04971 
04972       template<typename _UniformRandomNumberGenerator>
04973     void
04974     __generate(result_type* __f, result_type* __t,
04975            _UniformRandomNumberGenerator& __urng,
04976            const param_type& __p)
04977     { this->__generate_impl(__f, __t, __urng, __p); }
04978 
04979       /**
04980        * @brief Return true if two Weibull distributions have the same
04981        *        parameters.
04982        */
04983       friend bool
04984       operator==(const weibull_distribution& __d1,
04985          const weibull_distribution& __d2)
04986       { return __d1._M_param == __d2._M_param; }
04987 
04988     private:
04989       template<typename _ForwardIterator,
04990            typename _UniformRandomNumberGenerator>
04991     void
04992     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04993             _UniformRandomNumberGenerator& __urng,
04994             const param_type& __p);
04995 
04996       param_type _M_param;
04997     };
04998 
04999    /**
05000     * @brief Return true if two Weibull distributions have different
05001     *        parameters.
05002     */
05003   template<typename _RealType>
05004     inline bool
05005     operator!=(const std::weibull_distribution<_RealType>& __d1,
05006            const std::weibull_distribution<_RealType>& __d2)
05007     { return !(__d1 == __d2); }
05008 
05009   /**
05010    * @brief Inserts a %weibull_distribution random number distribution
05011    * @p __x into the output stream @p __os.
05012    *
05013    * @param __os An output stream.
05014    * @param __x  A %weibull_distribution random number distribution.
05015    *
05016    * @returns The output stream with the state of @p __x inserted or in
05017    * an error state.
05018    */
05019   template<typename _RealType, typename _CharT, typename _Traits>
05020     std::basic_ostream<_CharT, _Traits>&
05021     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05022            const std::weibull_distribution<_RealType>& __x);
05023 
05024   /**
05025    * @brief Extracts a %weibull_distribution random number distribution
05026    * @p __x from the input stream @p __is.
05027    *
05028    * @param __is An input stream.
05029    * @param __x A %weibull_distribution random number
05030    *            generator engine.
05031    *
05032    * @returns The input stream with @p __x extracted or in an error state.
05033    */
05034   template<typename _RealType, typename _CharT, typename _Traits>
05035     std::basic_istream<_CharT, _Traits>&
05036     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05037            std::weibull_distribution<_RealType>& __x);
05038 
05039 
05040   /**
05041    * @brief A extreme_value_distribution random number distribution.
05042    *
05043    * The formula for the normal probability mass function is
05044    * @f[
05045    *     p(x|a,b) = \frac{1}{b}
05046    *                \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) 
05047    * @f]
05048    */
05049   template<typename _RealType = double>
05050     class extreme_value_distribution
05051     {
05052       static_assert(std::is_floating_point<_RealType>::value,
05053             "template argument not a floating point type");
05054 
05055     public:
05056       /** The type of the range of the distribution. */
05057       typedef _RealType result_type;
05058       /** Parameter type. */
05059       struct param_type
05060       {
05061     typedef extreme_value_distribution<_RealType> distribution_type;
05062 
05063     explicit
05064     param_type(_RealType __a = _RealType(0),
05065            _RealType __b = _RealType(1))
05066     : _M_a(__a), _M_b(__b)
05067     { }
05068 
05069     _RealType
05070     a() const
05071     { return _M_a; }
05072 
05073     _RealType
05074     b() const
05075     { return _M_b; }
05076 
05077     friend bool
05078     operator==(const param_type& __p1, const param_type& __p2)
05079     { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
05080 
05081       private:
05082     _RealType _M_a;
05083     _RealType _M_b;
05084       };
05085 
05086       explicit
05087       extreme_value_distribution(_RealType __a = _RealType(0),
05088                  _RealType __b = _RealType(1))
05089       : _M_param(__a, __b)
05090       { }
05091 
05092       explicit
05093       extreme_value_distribution(const param_type& __p)
05094       : _M_param(__p)
05095       { }
05096 
05097       /**
05098        * @brief Resets the distribution state.
05099        */
05100       void
05101       reset()
05102       { }
05103 
05104       /**
05105        * @brief Return the @f$a@f$ parameter of the distribution.
05106        */
05107       _RealType
05108       a() const
05109       { return _M_param.a(); }
05110 
05111       /**
05112        * @brief Return the @f$b@f$ parameter of the distribution.
05113        */
05114       _RealType
05115       b() const
05116       { return _M_param.b(); }
05117 
05118       /**
05119        * @brief Returns the parameter set of the distribution.
05120        */
05121       param_type
05122       param() const
05123       { return _M_param; }
05124 
05125       /**
05126        * @brief Sets the parameter set of the distribution.
05127        * @param __param The new parameter set of the distribution.
05128        */
05129       void
05130       param(const param_type& __param)
05131       { _M_param = __param; }
05132 
05133       /**
05134        * @brief Returns the greatest lower bound value of the distribution.
05135        */
05136       result_type
05137       min() const
05138       { return std::numeric_limits<result_type>::min(); }
05139 
05140       /**
05141        * @brief Returns the least upper bound value of the distribution.
05142        */
05143       result_type
05144       max() const
05145       { return std::numeric_limits<result_type>::max(); }
05146 
05147       /**
05148        * @brief Generating functions.
05149        */
05150       template<typename _UniformRandomNumberGenerator>
05151     result_type
05152     operator()(_UniformRandomNumberGenerator& __urng)
05153     { return this->operator()(__urng, _M_param); }
05154 
05155       template<typename _UniformRandomNumberGenerator>
05156     result_type
05157     operator()(_UniformRandomNumberGenerator& __urng,
05158            const param_type& __p);
05159 
05160       template<typename _ForwardIterator,
05161            typename _UniformRandomNumberGenerator>
05162     void
05163     __generate(_ForwardIterator __f, _ForwardIterator __t,
05164            _UniformRandomNumberGenerator& __urng)
05165     { this->__generate(__f, __t, __urng, _M_param); }
05166 
05167       template<typename _ForwardIterator,
05168            typename _UniformRandomNumberGenerator>
05169     void
05170     __generate(_ForwardIterator __f, _ForwardIterator __t,
05171            _UniformRandomNumberGenerator& __urng,
05172            const param_type& __p)
05173     { this->__generate_impl(__f, __t, __urng, __p); }
05174 
05175       template<typename _UniformRandomNumberGenerator>
05176     void
05177     __generate(result_type* __f, result_type* __t,
05178            _UniformRandomNumberGenerator& __urng,
05179            const param_type& __p)
05180     { this->__generate_impl(__f, __t, __urng, __p); }
05181 
05182       /**
05183        * @brief Return true if two extreme value distributions have the same
05184        *        parameters.
05185        */
05186       friend bool
05187       operator==(const extreme_value_distribution& __d1,
05188          const extreme_value_distribution& __d2)
05189       { return __d1._M_param == __d2._M_param; }
05190 
05191     private:
05192       template<typename _ForwardIterator,
05193            typename _UniformRandomNumberGenerator>
05194     void
05195     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05196             _UniformRandomNumberGenerator& __urng,
05197             const param_type& __p);
05198 
05199       param_type _M_param;
05200     };
05201 
05202   /**
05203     * @brief Return true if two extreme value distributions have different
05204     *        parameters.
05205    */
05206   template<typename _RealType>
05207     inline bool
05208     operator!=(const std::extreme_value_distribution<_RealType>& __d1,
05209            const std::extreme_value_distribution<_RealType>& __d2)
05210     { return !(__d1 == __d2); }
05211 
05212   /**
05213    * @brief Inserts a %extreme_value_distribution random number distribution
05214    * @p __x into the output stream @p __os.
05215    *
05216    * @param __os An output stream.
05217    * @param __x  A %extreme_value_distribution random number distribution.
05218    *
05219    * @returns The output stream with the state of @p __x inserted or in
05220    * an error state.
05221    */
05222   template<typename _RealType, typename _CharT, typename _Traits>
05223     std::basic_ostream<_CharT, _Traits>&
05224     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05225            const std::extreme_value_distribution<_RealType>& __x);
05226 
05227   /**
05228    * @brief Extracts a %extreme_value_distribution random number
05229    *        distribution @p __x from the input stream @p __is.
05230    *
05231    * @param __is An input stream.
05232    * @param __x A %extreme_value_distribution random number
05233    *            generator engine.
05234    *
05235    * @returns The input stream with @p __x extracted or in an error state.
05236    */
05237   template<typename _RealType, typename _CharT, typename _Traits>
05238     std::basic_istream<_CharT, _Traits>&
05239     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05240            std::extreme_value_distribution<_RealType>& __x);
05241 
05242 
05243   /**
05244    * @brief A discrete_distribution random number distribution.
05245    *
05246    * The formula for the discrete probability mass function is
05247    *
05248    */
05249   template<typename _IntType = int>
05250     class discrete_distribution
05251     {
05252       static_assert(std::is_integral<_IntType>::value,
05253             "template argument not an integral type");
05254 
05255     public:
05256       /** The type of the range of the distribution. */
05257       typedef _IntType result_type;
05258       /** Parameter type. */
05259       struct param_type
05260       {
05261     typedef discrete_distribution<_IntType> distribution_type;
05262     friend class discrete_distribution<_IntType>;
05263 
05264     param_type()
05265     : _M_prob(), _M_cp()
05266     { }
05267 
05268     template<typename _InputIterator>
05269       param_type(_InputIterator __wbegin,
05270              _InputIterator __wend)
05271       : _M_prob(__wbegin, __wend), _M_cp()
05272       { _M_initialize(); }
05273 
05274     param_type(initializer_list<double> __wil)
05275     : _M_prob(__wil.begin(), __wil.end()), _M_cp()
05276     { _M_initialize(); }
05277 
05278     template<typename _Func>
05279       param_type(size_t __nw, double __xmin, double __xmax,
05280              _Func __fw);
05281 
05282     // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05283     param_type(const param_type&) = default;
05284     param_type& operator=(const param_type&) = default;
05285 
05286     std::vector<double>
05287     probabilities() const
05288     { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
05289 
05290     friend bool
05291     operator==(const param_type& __p1, const param_type& __p2)
05292     { return __p1._M_prob == __p2._M_prob; }
05293 
05294       private:
05295     void
05296     _M_initialize();
05297 
05298     std::vector<double> _M_prob;
05299     std::vector<double> _M_cp;
05300       };
05301 
05302       discrete_distribution()
05303       : _M_param()
05304       { }
05305 
05306       template<typename _InputIterator>
05307     discrete_distribution(_InputIterator __wbegin,
05308                   _InputIterator __wend)
05309     : _M_param(__wbegin, __wend)
05310     { }
05311 
05312       discrete_distribution(initializer_list<double> __wl)
05313       : _M_param(__wl)
05314       { }
05315 
05316       template<typename _Func>
05317     discrete_distribution(size_t __nw, double __xmin, double __xmax,
05318                   _Func __fw)
05319     : _M_param(__nw, __xmin, __xmax, __fw)
05320     { }
05321 
05322       explicit
05323       discrete_distribution(const param_type& __p)
05324       : _M_param(__p)
05325       { }
05326 
05327       /**
05328        * @brief Resets the distribution state.
05329        */
05330       void
05331       reset()
05332       { }
05333 
05334       /**
05335        * @brief Returns the probabilities of the distribution.
05336        */
05337       std::vector<double>
05338       probabilities() const
05339       {
05340     return _M_param._M_prob.empty()
05341       ? std::vector<double>(1, 1.0) : _M_param._M_prob;
05342       }
05343 
05344       /**
05345        * @brief Returns the parameter set of the distribution.
05346        */
05347       param_type
05348       param() const
05349       { return _M_param; }
05350 
05351       /**
05352        * @brief Sets the parameter set of the distribution.
05353        * @param __param The new parameter set of the distribution.
05354        */
05355       void
05356       param(const param_type& __param)
05357       { _M_param = __param; }
05358 
05359       /**
05360        * @brief Returns the greatest lower bound value of the distribution.
05361        */
05362       result_type
05363       min() const
05364       { return result_type(0); }
05365 
05366       /**
05367        * @brief Returns the least upper bound value of the distribution.
05368        */
05369       result_type
05370       max() const
05371       {
05372     return _M_param._M_prob.empty()
05373       ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
05374       }
05375 
05376       /**
05377        * @brief Generating functions.
05378        */
05379       template<typename _UniformRandomNumberGenerator>
05380     result_type
05381     operator()(_UniformRandomNumberGenerator& __urng)
05382     { return this->operator()(__urng, _M_param); }
05383 
05384       template<typename _UniformRandomNumberGenerator>
05385     result_type
05386     operator()(_UniformRandomNumberGenerator& __urng,
05387            const param_type& __p);
05388 
05389       template<typename _ForwardIterator,
05390            typename _UniformRandomNumberGenerator>
05391     void
05392     __generate(_ForwardIterator __f, _ForwardIterator __t,
05393            _UniformRandomNumberGenerator& __urng)
05394     { this->__generate(__f, __t, __urng, _M_param); }
05395 
05396       template<typename _ForwardIterator,
05397            typename _UniformRandomNumberGenerator>
05398     void
05399     __generate(_ForwardIterator __f, _ForwardIterator __t,
05400            _UniformRandomNumberGenerator& __urng,
05401            const param_type& __p)
05402     { this->__generate_impl(__f, __t, __urng, __p); }
05403 
05404       template<typename _UniformRandomNumberGenerator>
05405     void
05406     __generate(result_type* __f, result_type* __t,
05407            _UniformRandomNumberGenerator& __urng,
05408            const param_type& __p)
05409     { this->__generate_impl(__f, __t, __urng, __p); }
05410 
05411       /**
05412        * @brief Return true if two discrete distributions have the same
05413        *        parameters.
05414        */
05415       friend bool
05416       operator==(const discrete_distribution& __d1,
05417          const discrete_distribution& __d2)
05418       { return __d1._M_param == __d2._M_param; }
05419 
05420       /**
05421        * @brief Inserts a %discrete_distribution random number distribution
05422        * @p __x into the output stream @p __os.
05423        *
05424        * @param __os An output stream.
05425        * @param __x  A %discrete_distribution random number distribution.
05426        *
05427        * @returns The output stream with the state of @p __x inserted or in
05428        * an error state.
05429        */
05430       template<typename _IntType1, typename _CharT, typename _Traits>
05431     friend std::basic_ostream<_CharT, _Traits>&
05432     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05433            const std::discrete_distribution<_IntType1>& __x);
05434 
05435       /**
05436        * @brief Extracts a %discrete_distribution random number distribution
05437        * @p __x from the input stream @p __is.
05438        *
05439        * @param __is An input stream.
05440        * @param __x A %discrete_distribution random number
05441        *            generator engine.
05442        *
05443        * @returns The input stream with @p __x extracted or in an error
05444        *          state.
05445        */
05446       template<typename _IntType1, typename _CharT, typename _Traits>
05447     friend std::basic_istream<_CharT, _Traits>&
05448     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05449            std::discrete_distribution<_IntType1>& __x);
05450 
05451     private:
05452       template<typename _ForwardIterator,
05453            typename _UniformRandomNumberGenerator>
05454     void
05455     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05456             _UniformRandomNumberGenerator& __urng,
05457             const param_type& __p);
05458 
05459       param_type _M_param;
05460     };
05461 
05462   /**
05463     * @brief Return true if two discrete distributions have different
05464     *        parameters.
05465     */
05466   template<typename _IntType>
05467     inline bool
05468     operator!=(const std::discrete_distribution<_IntType>& __d1,
05469            const std::discrete_distribution<_IntType>& __d2)
05470     { return !(__d1 == __d2); }
05471 
05472 
05473   /**
05474    * @brief A piecewise_constant_distribution random number distribution.
05475    *
05476    * The formula for the piecewise constant probability mass function is
05477    *
05478    */
05479   template<typename _RealType = double>
05480     class piecewise_constant_distribution
05481     {
05482       static_assert(std::is_floating_point<_RealType>::value,
05483             "template argument not a floating point type");
05484 
05485     public:
05486       /** The type of the range of the distribution. */
05487       typedef _RealType result_type;
05488       /** Parameter type. */
05489       struct param_type
05490       {
05491     typedef piecewise_constant_distribution<_RealType> distribution_type;
05492     friend class piecewise_constant_distribution<_RealType>;
05493 
05494     param_type()
05495     : _M_int(), _M_den(), _M_cp()
05496     { }
05497 
05498     template<typename _InputIteratorB, typename _InputIteratorW>
05499       param_type(_InputIteratorB __bfirst,
05500              _InputIteratorB __bend,
05501              _InputIteratorW __wbegin);
05502 
05503     template<typename _Func>
05504       param_type(initializer_list<_RealType> __bi, _Func __fw);
05505 
05506     template<typename _Func>
05507       param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
05508              _Func __fw);
05509 
05510     // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05511     param_type(const param_type&) = default;
05512     param_type& operator=(const param_type&) = default;
05513 
05514     std::vector<_RealType>
05515     intervals() const
05516     {
05517       if (_M_int.empty())
05518         {
05519           std::vector<_RealType> __tmp(2);
05520           __tmp[1] = _RealType(1);
05521           return __tmp;
05522         }
05523       else
05524         return _M_int;
05525     }
05526 
05527     std::vector<double>
05528     densities() const
05529     { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
05530 
05531     friend bool
05532     operator==(const param_type& __p1, const param_type& __p2)
05533     { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
05534 
05535       private:
05536     void
05537     _M_initialize();
05538 
05539     std::vector<_RealType> _M_int;
05540     std::vector<double> _M_den;
05541     std::vector<double> _M_cp;
05542       };
05543 
05544       explicit
05545       piecewise_constant_distribution()
05546       : _M_param()
05547       { }
05548 
05549       template<typename _InputIteratorB, typename _InputIteratorW>
05550     piecewise_constant_distribution(_InputIteratorB __bfirst,
05551                     _InputIteratorB __bend,
05552                     _InputIteratorW __wbegin)
05553     : _M_param(__bfirst, __bend, __wbegin)
05554     { }
05555 
05556       template<typename _Func>
05557     piecewise_constant_distribution(initializer_list<_RealType> __bl,
05558                     _Func __fw)
05559     : _M_param(__bl, __fw)
05560     { }
05561 
05562       template<typename _Func>
05563     piecewise_constant_distribution(size_t __nw,
05564                     _RealType __xmin, _RealType __xmax,
05565                     _Func __fw)
05566     : _M_param(__nw, __xmin, __xmax, __fw)
05567     { }
05568 
05569       explicit
05570       piecewise_constant_distribution(const param_type& __p)
05571       : _M_param(__p)
05572       { }
05573 
05574       /**
05575        * @brief Resets the distribution state.
05576        */
05577       void
05578       reset()
05579       { }
05580 
05581       /**
05582        * @brief Returns a vector of the intervals.
05583        */
05584       std::vector<_RealType>
05585       intervals() const
05586       {
05587     if (_M_param._M_int.empty())
05588       {
05589         std::vector<_RealType> __tmp(2);
05590         __tmp[1] = _RealType(1);
05591         return __tmp;
05592       }
05593     else
05594       return _M_param._M_int;
05595       }
05596 
05597       /**
05598        * @brief Returns a vector of the probability densities.
05599        */
05600       std::vector<double>
05601       densities() const
05602       {
05603     return _M_param._M_den.empty()
05604       ? std::vector<double>(1, 1.0) : _M_param._M_den;
05605       }
05606 
05607       /**
05608        * @brief Returns the parameter set of the distribution.
05609        */
05610       param_type
05611       param() const
05612       { return _M_param; }
05613 
05614       /**
05615        * @brief Sets the parameter set of the distribution.
05616        * @param __param The new parameter set of the distribution.
05617        */
05618       void
05619       param(const param_type& __param)
05620       { _M_param = __param; }
05621 
05622       /**
05623        * @brief Returns the greatest lower bound value of the distribution.
05624        */
05625       result_type
05626       min() const
05627       {
05628     return _M_param._M_int.empty()
05629       ? result_type(0) : _M_param._M_int.front();
05630       }
05631 
05632       /**
05633        * @brief Returns the least upper bound value of the distribution.
05634        */
05635       result_type
05636       max() const
05637       {
05638     return _M_param._M_int.empty()
05639       ? result_type(1) : _M_param._M_int.back();
05640       }
05641 
05642       /**
05643        * @brief Generating functions.
05644        */
05645       template<typename _UniformRandomNumberGenerator>
05646     result_type
05647     operator()(_UniformRandomNumberGenerator& __urng)
05648     { return this->operator()(__urng, _M_param); }
05649 
05650       template<typename _UniformRandomNumberGenerator>
05651     result_type
05652     operator()(_UniformRandomNumberGenerator& __urng,
05653            const param_type& __p);
05654 
05655       template<typename _ForwardIterator,
05656            typename _UniformRandomNumberGenerator>
05657     void
05658     __generate(_ForwardIterator __f, _ForwardIterator __t,
05659            _UniformRandomNumberGenerator& __urng)
05660     { this->__generate(__f, __t, __urng, _M_param); }
05661 
05662       template<typename _ForwardIterator,
05663            typename _UniformRandomNumberGenerator>
05664     void
05665     __generate(_ForwardIterator __f, _ForwardIterator __t,
05666            _UniformRandomNumberGenerator& __urng,
05667            const param_type& __p)
05668     { this->__generate_impl(__f, __t, __urng, __p); }
05669 
05670       template<typename _UniformRandomNumberGenerator>
05671     void
05672     __generate(result_type* __f, result_type* __t,
05673            _UniformRandomNumberGenerator& __urng,
05674            const param_type& __p)
05675     { this->__generate_impl(__f, __t, __urng, __p); }
05676 
05677       /**
05678        * @brief Return true if two piecewise constant distributions have the
05679        *        same parameters.
05680        */
05681       friend bool
05682       operator==(const piecewise_constant_distribution& __d1,
05683          const piecewise_constant_distribution& __d2)
05684       { return __d1._M_param == __d2._M_param; }
05685 
05686       /**
05687        * @brief Inserts a %piecewise_constan_distribution random
05688        *        number distribution @p __x into the output stream @p __os.
05689        *
05690        * @param __os An output stream.
05691        * @param __x  A %piecewise_constan_distribution random number
05692        *             distribution.
05693        *
05694        * @returns The output stream with the state of @p __x inserted or in
05695        * an error state.
05696        */
05697       template<typename _RealType1, typename _CharT, typename _Traits>
05698     friend std::basic_ostream<_CharT, _Traits>&
05699     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05700            const std::piecewise_constant_distribution<_RealType1>& __x);
05701 
05702       /**
05703        * @brief Extracts a %piecewise_constan_distribution random
05704        *        number distribution @p __x from the input stream @p __is.
05705        *
05706        * @param __is An input stream.
05707        * @param __x A %piecewise_constan_distribution random number
05708        *            generator engine.
05709        *
05710        * @returns The input stream with @p __x extracted or in an error
05711        *          state.
05712        */
05713       template<typename _RealType1, typename _CharT, typename _Traits>
05714     friend std::basic_istream<_CharT, _Traits>&
05715     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05716            std::piecewise_constant_distribution<_RealType1>& __x);
05717 
05718     private:
05719       template<typename _ForwardIterator,
05720            typename _UniformRandomNumberGenerator>
05721     void
05722     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05723             _UniformRandomNumberGenerator& __urng,
05724             const param_type& __p);
05725 
05726       param_type _M_param;
05727     };
05728 
05729   /**
05730     * @brief Return true if two piecewise constant distributions have 
05731     *        different parameters.
05732    */
05733   template<typename _RealType>
05734     inline bool
05735     operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
05736            const std::piecewise_constant_distribution<_RealType>& __d2)
05737     { return !(__d1 == __d2); }
05738 
05739 
05740   /**
05741    * @brief A piecewise_linear_distribution random number distribution.
05742    *
05743    * The formula for the piecewise linear probability mass function is
05744    *
05745    */
05746   template<typename _RealType = double>
05747     class piecewise_linear_distribution
05748     {
05749       static_assert(std::is_floating_point<_RealType>::value,
05750             "template argument not a floating point type");
05751 
05752     public:
05753       /** The type of the range of the distribution. */
05754       typedef _RealType result_type;
05755       /** Parameter type. */
05756       struct param_type
05757       {
05758     typedef piecewise_linear_distribution<_RealType> distribution_type;
05759     friend class piecewise_linear_distribution<_RealType>;
05760 
05761     param_type()
05762     : _M_int(), _M_den(), _M_cp(), _M_m()
05763     { }
05764 
05765     template<typename _InputIteratorB, typename _InputIteratorW>
05766       param_type(_InputIteratorB __bfirst,
05767              _InputIteratorB __bend,
05768              _InputIteratorW __wbegin);
05769 
05770     template<typename _Func>
05771       param_type(initializer_list<_RealType> __bl, _Func __fw);
05772 
05773     template<typename _Func>
05774       param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
05775              _Func __fw);
05776 
05777     // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05778     param_type(const param_type&) = default;
05779     param_type& operator=(const param_type&) = default;
05780 
05781     std::vector<_RealType>
05782     intervals() const
05783     {
05784       if (_M_int.empty())
05785         {
05786           std::vector<_RealType> __tmp(2);
05787           __tmp[1] = _RealType(1);
05788           return __tmp;
05789         }
05790       else
05791         return _M_int;
05792     }
05793 
05794     std::vector<double>
05795     densities() const
05796     { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
05797 
05798     friend bool
05799     operator==(const param_type& __p1, const param_type& __p2)
05800     { return (__p1._M_int == __p2._M_int
05801           && __p1._M_den == __p2._M_den); }
05802 
05803       private:
05804     void
05805     _M_initialize();
05806 
05807     std::vector<_RealType> _M_int;
05808     std::vector<double> _M_den;
05809     std::vector<double> _M_cp;
05810     std::vector<double> _M_m;
05811       };
05812 
05813       explicit
05814       piecewise_linear_distribution()
05815       : _M_param()
05816       { }
05817 
05818       template<typename _InputIteratorB, typename _InputIteratorW>
05819     piecewise_linear_distribution(_InputIteratorB __bfirst,
05820                       _InputIteratorB __bend,
05821                       _InputIteratorW __wbegin)
05822     : _M_param(__bfirst, __bend, __wbegin)
05823     { }
05824 
05825       template<typename _Func>
05826     piecewise_linear_distribution(initializer_list<_RealType> __bl,
05827                       _Func __fw)
05828     : _M_param(__bl, __fw)
05829     { }
05830 
05831       template<typename _Func>
05832     piecewise_linear_distribution(size_t __nw,
05833                       _RealType __xmin, _RealType __xmax,
05834                       _Func __fw)
05835     : _M_param(__nw, __xmin, __xmax, __fw)
05836     { }
05837 
05838       explicit
05839       piecewise_linear_distribution(const param_type& __p)
05840       : _M_param(__p)
05841       { }
05842 
05843       /**
05844        * Resets the distribution state.
05845        */
05846       void
05847       reset()
05848       { }
05849 
05850       /**
05851        * @brief Return the intervals of the distribution.
05852        */
05853       std::vector<_RealType>
05854       intervals() const
05855       {
05856     if (_M_param._M_int.empty())
05857       {
05858         std::vector<_RealType> __tmp(2);
05859         __tmp[1] = _RealType(1);
05860         return __tmp;
05861       }
05862     else
05863       return _M_param._M_int;
05864       }
05865 
05866       /**
05867        * @brief Return a vector of the probability densities of the
05868        *        distribution.
05869        */
05870       std::vector<double>
05871       densities() const
05872       {
05873     return _M_param._M_den.empty()
05874       ? std::vector<double>(2, 1.0) : _M_param._M_den;
05875       }
05876 
05877       /**
05878        * @brief Returns the parameter set of the distribution.
05879        */
05880       param_type
05881       param() const
05882       { return _M_param; }
05883 
05884       /**
05885        * @brief Sets the parameter set of the distribution.
05886        * @param __param The new parameter set of the distribution.
05887        */
05888       void
05889       param(const param_type& __param)
05890       { _M_param = __param; }
05891 
05892       /**
05893        * @brief Returns the greatest lower bound value of the distribution.
05894        */
05895       result_type
05896       min() const
05897       {
05898     return _M_param._M_int.empty()
05899       ? result_type(0) : _M_param._M_int.front();
05900       }
05901 
05902       /**
05903        * @brief Returns the least upper bound value of the distribution.
05904        */
05905       result_type
05906       max() const
05907       {
05908     return _M_param._M_int.empty()
05909       ? result_type(1) : _M_param._M_int.back();
05910       }
05911 
05912       /**
05913        * @brief Generating functions.
05914        */
05915       template<typename _UniformRandomNumberGenerator>
05916     result_type
05917     operator()(_UniformRandomNumberGenerator& __urng)
05918     { return this->operator()(__urng, _M_param); }
05919 
05920       template<typename _UniformRandomNumberGenerator>
05921     result_type
05922     operator()(_UniformRandomNumberGenerator& __urng,
05923            const param_type& __p);
05924 
05925       template<typename _ForwardIterator,
05926            typename _UniformRandomNumberGenerator>
05927     void
05928     __generate(_ForwardIterator __f, _ForwardIterator __t,
05929            _UniformRandomNumberGenerator& __urng)
05930     { this->__generate(__f, __t, __urng, _M_param); }
05931 
05932       template<typename _ForwardIterator,
05933            typename _UniformRandomNumberGenerator>
05934     void
05935     __generate(_ForwardIterator __f, _ForwardIterator __t,
05936            _UniformRandomNumberGenerator& __urng,
05937            const param_type& __p)
05938     { this->__generate_impl(__f, __t, __urng, __p); }
05939 
05940       template<typename _UniformRandomNumberGenerator>
05941     void
05942     __generate(result_type* __f, result_type* __t,
05943            _UniformRandomNumberGenerator& __urng,
05944            const param_type& __p)
05945     { this->__generate_impl(__f, __t, __urng, __p); }
05946 
05947       /**
05948        * @brief Return true if two piecewise linear distributions have the
05949        *        same parameters.
05950        */
05951       friend bool
05952       operator==(const piecewise_linear_distribution& __d1,
05953          const piecewise_linear_distribution& __d2)
05954       { return __d1._M_param == __d2._M_param; }
05955 
05956       /**
05957        * @brief Inserts a %piecewise_linear_distribution random number
05958        *        distribution @p __x into the output stream @p __os.
05959        *
05960        * @param __os An output stream.
05961        * @param __x  A %piecewise_linear_distribution random number
05962        *             distribution.
05963        *
05964        * @returns The output stream with the state of @p __x inserted or in
05965        *          an error state.
05966        */
05967       template<typename _RealType1, typename _CharT, typename _Traits>
05968     friend std::basic_ostream<_CharT, _Traits>&
05969     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05970            const std::piecewise_linear_distribution<_RealType1>& __x);
05971 
05972       /**
05973        * @brief Extracts a %piecewise_linear_distribution random number
05974        *        distribution @p __x from the input stream @p __is.
05975        *
05976        * @param __is An input stream.
05977        * @param __x  A %piecewise_linear_distribution random number
05978        *             generator engine.
05979        *
05980        * @returns The input stream with @p __x extracted or in an error
05981        *          state.
05982        */
05983       template<typename _RealType1, typename _CharT, typename _Traits>
05984     friend std::basic_istream<_CharT, _Traits>&
05985     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05986            std::piecewise_linear_distribution<_RealType1>& __x);
05987 
05988     private:
05989       template<typename _ForwardIterator,
05990            typename _UniformRandomNumberGenerator>
05991     void
05992     __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05993             _UniformRandomNumberGenerator& __urng,
05994             const param_type& __p);
05995 
05996       param_type _M_param;
05997     };
05998 
05999   /**
06000     * @brief Return true if two piecewise linear distributions have
06001     *        different parameters.
06002    */
06003   template<typename _RealType>
06004     inline bool
06005     operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
06006            const std::piecewise_linear_distribution<_RealType>& __d2)
06007     { return !(__d1 == __d2); }
06008 
06009 
06010   /* @} */ // group random_distributions_poisson
06011 
06012   /* @} */ // group random_distributions
06013 
06014   /**
06015    * @addtogroup random_utilities Random Number Utilities
06016    * @ingroup random
06017    * @{
06018    */
06019 
06020   /**
06021    * @brief The seed_seq class generates sequences of seeds for random
06022    *        number generators.
06023    */
06024   class seed_seq
06025   {
06026 
06027   public:
06028     /** The type of the seed vales. */
06029     typedef uint_least32_t result_type;
06030 
06031     /** Default constructor. */
06032     seed_seq()
06033     : _M_v()
06034     { }
06035 
06036     template<typename _IntType>
06037       seed_seq(std::initializer_list<_IntType> il);
06038 
06039     template<typename _InputIterator>
06040       seed_seq(_InputIterator __begin, _InputIterator __end);
06041 
06042     // generating functions
06043     template<typename _RandomAccessIterator>
06044       void
06045       generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
06046 
06047     // property functions
06048     size_t size() const
06049     { return _M_v.size(); }
06050 
06051     template<typename OutputIterator>
06052       void
06053       param(OutputIterator __dest) const
06054       { std::copy(_M_v.begin(), _M_v.end(), __dest); }
06055 
06056   private:
06057     ///
06058     std::vector<result_type> _M_v;
06059   };
06060 
06061   /* @} */ // group random_utilities
06062 
06063   /* @} */ // group random
06064 
06065 _GLIBCXX_END_NAMESPACE_VERSION
06066 } // namespace std
06067 
06068 #endif