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