libstdc++
random.h
Go to the documentation of this file.
00001 // random number generation -*- C++ -*-
00002 
00003 // Copyright (C) 2009-2015 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 not 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, "template argument "
00239                     "substituting _UIntType not 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, "template argument "
00447                     "substituting _UIntType not 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, "template argument "
00662                     "substituting _UIntType not an unsigned integral type");
00663       static_assert(0u < __s && __s < __r,
00664                     "template argument substituting __s out of bounds");
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, "template argument "
01069                     "substituting _UIntType not 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 __w.
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                     "template argument not a floating point type");
01706 
01707     public:
01708       /** The type of the range of the distribution. */
01709       typedef _RealType result_type;
01710       /** Parameter type. */
01711       struct param_type
01712       {
01713         typedef uniform_real_distribution<_RealType> distribution_type;
01714 
01715         explicit
01716         param_type(_RealType __a = _RealType(0),
01717                    _RealType __b = _RealType(1))
01718         : _M_a(__a), _M_b(__b)
01719         {
01720           _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
01721         }
01722 
01723         result_type
01724         a() const
01725         { return _M_a; }
01726 
01727         result_type
01728         b() const
01729         { return _M_b; }
01730 
01731         friend bool
01732         operator==(const param_type& __p1, const param_type& __p2)
01733         { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
01734 
01735       private:
01736         _RealType _M_a;
01737         _RealType _M_b;
01738       };
01739 
01740     public:
01741       /**
01742        * @brief Constructs a uniform_real_distribution object.
01743        *
01744        * @param __a [IN]  The lower bound of the distribution.
01745        * @param __b [IN]  The upper bound of the distribution.
01746        */
01747       explicit
01748       uniform_real_distribution(_RealType __a = _RealType(0),
01749                                 _RealType __b = _RealType(1))
01750       : _M_param(__a, __b)
01751       { }
01752 
01753       explicit
01754       uniform_real_distribution(const param_type& __p)
01755       : _M_param(__p)
01756       { }
01757 
01758       /**
01759        * @brief Resets the distribution state.
01760        *
01761        * Does nothing for the uniform real distribution.
01762        */
01763       void
01764       reset() { }
01765 
01766       result_type
01767       a() const
01768       { return _M_param.a(); }
01769 
01770       result_type
01771       b() const
01772       { return _M_param.b(); }
01773 
01774       /**
01775        * @brief Returns the parameter set of the distribution.
01776        */
01777       param_type
01778       param() const
01779       { return _M_param; }
01780 
01781       /**
01782        * @brief Sets the parameter set of the distribution.
01783        * @param __param The new parameter set of the distribution.
01784        */
01785       void
01786       param(const param_type& __param)
01787       { _M_param = __param; }
01788 
01789       /**
01790        * @brief Returns the inclusive lower bound of the distribution range.
01791        */
01792       result_type
01793       min() const
01794       { return this->a(); }
01795 
01796       /**
01797        * @brief Returns the inclusive upper bound of the distribution range.
01798        */
01799       result_type
01800       max() const
01801       { return this->b(); }
01802 
01803       /**
01804        * @brief Generating functions.
01805        */
01806       template<typename _UniformRandomNumberGenerator>
01807         result_type
01808         operator()(_UniformRandomNumberGenerator& __urng)
01809         { return this->operator()(__urng, _M_param); }
01810 
01811       template<typename _UniformRandomNumberGenerator>
01812         result_type
01813         operator()(_UniformRandomNumberGenerator& __urng,
01814                    const param_type& __p)
01815         {
01816           __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
01817             __aurng(__urng);
01818           return (__aurng() * (__p.b() - __p.a())) + __p.a();
01819         }
01820 
01821       template<typename _ForwardIterator,
01822                typename _UniformRandomNumberGenerator>
01823         void
01824         __generate(_ForwardIterator __f, _ForwardIterator __t,
01825                    _UniformRandomNumberGenerator& __urng)
01826         { this->__generate(__f, __t, __urng, _M_param); }
01827 
01828       template<typename _ForwardIterator,
01829                typename _UniformRandomNumberGenerator>
01830         void
01831         __generate(_ForwardIterator __f, _ForwardIterator __t,
01832                    _UniformRandomNumberGenerator& __urng,
01833                    const param_type& __p)
01834         { this->__generate_impl(__f, __t, __urng, __p); }
01835 
01836       template<typename _UniformRandomNumberGenerator>
01837         void
01838         __generate(result_type* __f, result_type* __t,
01839                    _UniformRandomNumberGenerator& __urng,
01840                    const param_type& __p)
01841         { this->__generate_impl(__f, __t, __urng, __p); }
01842 
01843       /**
01844        * @brief Return true if two uniform real distributions have
01845        *        the same parameters.
01846        */
01847       friend bool
01848       operator==(const uniform_real_distribution& __d1,
01849                  const uniform_real_distribution& __d2)
01850       { return __d1._M_param == __d2._M_param; }
01851 
01852     private:
01853       template<typename _ForwardIterator,
01854                typename _UniformRandomNumberGenerator>
01855         void
01856         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
01857                         _UniformRandomNumberGenerator& __urng,
01858                         const param_type& __p);
01859 
01860       param_type _M_param;
01861     };
01862 
01863   /**
01864    * @brief Return true if two uniform real distributions have
01865    *        different parameters.
01866    */
01867   template<typename _IntType>
01868     inline bool
01869     operator!=(const std::uniform_real_distribution<_IntType>& __d1,
01870                const std::uniform_real_distribution<_IntType>& __d2)
01871     { return !(__d1 == __d2); }
01872 
01873   /**
01874    * @brief Inserts a %uniform_real_distribution random number
01875    *        distribution @p __x into the output stream @p __os.
01876    *
01877    * @param __os An output stream.
01878    * @param __x  A %uniform_real_distribution random number distribution.
01879    *
01880    * @returns The output stream with the state of @p __x inserted or in
01881    *          an error state.
01882    */
01883   template<typename _RealType, typename _CharT, typename _Traits>
01884     std::basic_ostream<_CharT, _Traits>&
01885     operator<<(std::basic_ostream<_CharT, _Traits>&,
01886                const std::uniform_real_distribution<_RealType>&);
01887 
01888   /**
01889    * @brief Extracts a %uniform_real_distribution random number distribution
01890    * @p __x from the input stream @p __is.
01891    *
01892    * @param __is An input stream.
01893    * @param __x  A %uniform_real_distribution random number generator engine.
01894    *
01895    * @returns The input stream with @p __x extracted or in an error state.
01896    */
01897   template<typename _RealType, typename _CharT, typename _Traits>
01898     std::basic_istream<_CharT, _Traits>&
01899     operator>>(std::basic_istream<_CharT, _Traits>&,
01900                std::uniform_real_distribution<_RealType>&);
01901 
01902   /* @} */ // group random_distributions_uniform
01903 
01904   /**
01905    * @addtogroup random_distributions_normal Normal Distributions
01906    * @ingroup random_distributions
01907    * @{
01908    */
01909 
01910   /**
01911    * @brief A normal continuous distribution for random numbers.
01912    *
01913    * The formula for the normal probability density function is
01914    * @f[
01915    *     p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
01916    *            e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } 
01917    * @f]
01918    */
01919   template<typename _RealType = double>
01920     class normal_distribution
01921     {
01922       static_assert(std::is_floating_point<_RealType>::value,
01923                     "template argument not a floating point type");
01924 
01925     public:
01926       /** The type of the range of the distribution. */
01927       typedef _RealType result_type;
01928       /** Parameter type. */
01929       struct param_type
01930       {
01931         typedef normal_distribution<_RealType> distribution_type;
01932 
01933         explicit
01934         param_type(_RealType __mean = _RealType(0),
01935                    _RealType __stddev = _RealType(1))
01936         : _M_mean(__mean), _M_stddev(__stddev)
01937         {
01938           _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
01939         }
01940 
01941         _RealType
01942         mean() const
01943         { return _M_mean; }
01944 
01945         _RealType
01946         stddev() const
01947         { return _M_stddev; }
01948 
01949         friend bool
01950         operator==(const param_type& __p1, const param_type& __p2)
01951         { return (__p1._M_mean == __p2._M_mean
01952                   && __p1._M_stddev == __p2._M_stddev); }
01953 
01954       private:
01955         _RealType _M_mean;
01956         _RealType _M_stddev;
01957       };
01958 
01959     public:
01960       /**
01961        * Constructs a normal distribution with parameters @f$mean@f$ and
01962        * standard deviation.
01963        */
01964       explicit
01965       normal_distribution(result_type __mean = result_type(0),
01966                           result_type __stddev = result_type(1))
01967       : _M_param(__mean, __stddev), _M_saved_available(false)
01968       { }
01969 
01970       explicit
01971       normal_distribution(const param_type& __p)
01972       : _M_param(__p), _M_saved_available(false)
01973       { }
01974 
01975       /**
01976        * @brief Resets the distribution state.
01977        */
01978       void
01979       reset()
01980       { _M_saved_available = false; }
01981 
01982       /**
01983        * @brief Returns the mean of the distribution.
01984        */
01985       _RealType
01986       mean() const
01987       { return _M_param.mean(); }
01988 
01989       /**
01990        * @brief Returns the standard deviation of the distribution.
01991        */
01992       _RealType
01993       stddev() const
01994       { return _M_param.stddev(); }
01995 
01996       /**
01997        * @brief Returns the parameter set of the distribution.
01998        */
01999       param_type
02000       param() const
02001       { return _M_param; }
02002 
02003       /**
02004        * @brief Sets the parameter set of the distribution.
02005        * @param __param The new parameter set of the distribution.
02006        */
02007       void
02008       param(const param_type& __param)
02009       { _M_param = __param; }
02010 
02011       /**
02012        * @brief Returns the greatest lower bound value of the distribution.
02013        */
02014       result_type
02015       min() const
02016       { return std::numeric_limits<result_type>::lowest(); }
02017 
02018       /**
02019        * @brief Returns the least upper bound value of the distribution.
02020        */
02021       result_type
02022       max() const
02023       { return std::numeric_limits<result_type>::max(); }
02024 
02025       /**
02026        * @brief Generating functions.
02027        */
02028       template<typename _UniformRandomNumberGenerator>
02029         result_type
02030         operator()(_UniformRandomNumberGenerator& __urng)
02031         { return this->operator()(__urng, _M_param); }
02032 
02033       template<typename _UniformRandomNumberGenerator>
02034         result_type
02035         operator()(_UniformRandomNumberGenerator& __urng,
02036                    const param_type& __p);
02037 
02038       template<typename _ForwardIterator,
02039                typename _UniformRandomNumberGenerator>
02040         void
02041         __generate(_ForwardIterator __f, _ForwardIterator __t,
02042                    _UniformRandomNumberGenerator& __urng)
02043         { this->__generate(__f, __t, __urng, _M_param); }
02044 
02045       template<typename _ForwardIterator,
02046                typename _UniformRandomNumberGenerator>
02047         void
02048         __generate(_ForwardIterator __f, _ForwardIterator __t,
02049                    _UniformRandomNumberGenerator& __urng,
02050                    const param_type& __p)
02051         { this->__generate_impl(__f, __t, __urng, __p); }
02052 
02053       template<typename _UniformRandomNumberGenerator>
02054         void
02055         __generate(result_type* __f, result_type* __t,
02056                    _UniformRandomNumberGenerator& __urng,
02057                    const param_type& __p)
02058         { this->__generate_impl(__f, __t, __urng, __p); }
02059 
02060       /**
02061        * @brief Return true if two normal distributions have
02062        *        the same parameters and the sequences that would
02063        *        be generated are equal.
02064        */
02065       template<typename _RealType1>
02066         friend bool
02067         operator==(const std::normal_distribution<_RealType1>& __d1,
02068                    const std::normal_distribution<_RealType1>& __d2);
02069 
02070       /**
02071        * @brief Inserts a %normal_distribution random number distribution
02072        * @p __x into the output stream @p __os.
02073        *
02074        * @param __os An output stream.
02075        * @param __x  A %normal_distribution random number distribution.
02076        *
02077        * @returns The output stream with the state of @p __x inserted or in
02078        * an error state.
02079        */
02080       template<typename _RealType1, typename _CharT, typename _Traits>
02081         friend std::basic_ostream<_CharT, _Traits>&
02082         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02083                    const std::normal_distribution<_RealType1>& __x);
02084 
02085       /**
02086        * @brief Extracts a %normal_distribution random number distribution
02087        * @p __x from the input stream @p __is.
02088        *
02089        * @param __is An input stream.
02090        * @param __x  A %normal_distribution random number generator engine.
02091        *
02092        * @returns The input stream with @p __x extracted or in an error
02093        *          state.
02094        */
02095       template<typename _RealType1, typename _CharT, typename _Traits>
02096         friend std::basic_istream<_CharT, _Traits>&
02097         operator>>(std::basic_istream<_CharT, _Traits>& __is,
02098                    std::normal_distribution<_RealType1>& __x);
02099 
02100     private:
02101       template<typename _ForwardIterator,
02102                typename _UniformRandomNumberGenerator>
02103         void
02104         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02105                         _UniformRandomNumberGenerator& __urng,
02106                         const param_type& __p);
02107 
02108       param_type  _M_param;
02109       result_type _M_saved;
02110       bool        _M_saved_available;
02111     };
02112 
02113   /**
02114    * @brief Return true if two normal distributions are different.
02115    */
02116   template<typename _RealType>
02117     inline bool
02118     operator!=(const std::normal_distribution<_RealType>& __d1,
02119                const std::normal_distribution<_RealType>& __d2)
02120     { return !(__d1 == __d2); }
02121 
02122 
02123   /**
02124    * @brief A lognormal_distribution random number distribution.
02125    *
02126    * The formula for the normal probability mass function is
02127    * @f[
02128    *     p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
02129    *                \exp{-\frac{(\ln{x} - m)^2}{2s^2}} 
02130    * @f]
02131    */
02132   template<typename _RealType = double>
02133     class lognormal_distribution
02134     {
02135       static_assert(std::is_floating_point<_RealType>::value,
02136                     "template argument not a floating point type");
02137 
02138     public:
02139       /** The type of the range of the distribution. */
02140       typedef _RealType result_type;
02141       /** Parameter type. */
02142       struct param_type
02143       {
02144         typedef lognormal_distribution<_RealType> distribution_type;
02145 
02146         explicit
02147         param_type(_RealType __m = _RealType(0),
02148                    _RealType __s = _RealType(1))
02149         : _M_m(__m), _M_s(__s)
02150         { }
02151 
02152         _RealType
02153         m() const
02154         { return _M_m; }
02155 
02156         _RealType
02157         s() const
02158         { return _M_s; }
02159 
02160         friend bool
02161         operator==(const param_type& __p1, const param_type& __p2)
02162         { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
02163 
02164       private:
02165         _RealType _M_m;
02166         _RealType _M_s;
02167       };
02168 
02169       explicit
02170       lognormal_distribution(_RealType __m = _RealType(0),
02171                              _RealType __s = _RealType(1))
02172       : _M_param(__m, __s), _M_nd()
02173       { }
02174 
02175       explicit
02176       lognormal_distribution(const param_type& __p)
02177       : _M_param(__p), _M_nd()
02178       { }
02179 
02180       /**
02181        * Resets the distribution state.
02182        */
02183       void
02184       reset()
02185       { _M_nd.reset(); }
02186 
02187       /**
02188        *
02189        */
02190       _RealType
02191       m() const
02192       { return _M_param.m(); }
02193 
02194       _RealType
02195       s() const
02196       { return _M_param.s(); }
02197 
02198       /**
02199        * @brief Returns the parameter set of the distribution.
02200        */
02201       param_type
02202       param() const
02203       { return _M_param; }
02204 
02205       /**
02206        * @brief Sets the parameter set of the distribution.
02207        * @param __param The new parameter set of the distribution.
02208        */
02209       void
02210       param(const param_type& __param)
02211       { _M_param = __param; }
02212 
02213       /**
02214        * @brief Returns the greatest lower bound value of the distribution.
02215        */
02216       result_type
02217       min() const
02218       { return result_type(0); }
02219 
02220       /**
02221        * @brief Returns the least upper bound value of the distribution.
02222        */
02223       result_type
02224       max() const
02225       { return std::numeric_limits<result_type>::max(); }
02226 
02227       /**
02228        * @brief Generating functions.
02229        */
02230       template<typename _UniformRandomNumberGenerator>
02231         result_type
02232         operator()(_UniformRandomNumberGenerator& __urng)
02233         { return this->operator()(__urng, _M_param); }
02234 
02235       template<typename _UniformRandomNumberGenerator>
02236         result_type
02237         operator()(_UniformRandomNumberGenerator& __urng,
02238                    const param_type& __p)
02239         { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
02240 
02241       template<typename _ForwardIterator,
02242                typename _UniformRandomNumberGenerator>
02243         void
02244         __generate(_ForwardIterator __f, _ForwardIterator __t,
02245                    _UniformRandomNumberGenerator& __urng)
02246         { this->__generate(__f, __t, __urng, _M_param); }
02247 
02248       template<typename _ForwardIterator,
02249                typename _UniformRandomNumberGenerator>
02250         void
02251         __generate(_ForwardIterator __f, _ForwardIterator __t,
02252                    _UniformRandomNumberGenerator& __urng,
02253                    const param_type& __p)
02254         { this->__generate_impl(__f, __t, __urng, __p); }
02255 
02256       template<typename _UniformRandomNumberGenerator>
02257         void
02258         __generate(result_type* __f, result_type* __t,
02259                    _UniformRandomNumberGenerator& __urng,
02260                    const param_type& __p)
02261         { this->__generate_impl(__f, __t, __urng, __p); }
02262 
02263       /**
02264        * @brief Return true if two lognormal distributions have
02265        *        the same parameters and the sequences that would
02266        *        be generated are equal.
02267        */
02268       friend bool
02269       operator==(const lognormal_distribution& __d1,
02270                  const lognormal_distribution& __d2)
02271       { return (__d1._M_param == __d2._M_param
02272                 && __d1._M_nd == __d2._M_nd); }
02273 
02274       /**
02275        * @brief Inserts a %lognormal_distribution random number distribution
02276        * @p __x into the output stream @p __os.
02277        *
02278        * @param __os An output stream.
02279        * @param __x  A %lognormal_distribution random number distribution.
02280        *
02281        * @returns The output stream with the state of @p __x inserted or in
02282        * an error state.
02283        */
02284       template<typename _RealType1, typename _CharT, typename _Traits>
02285         friend std::basic_ostream<_CharT, _Traits>&
02286         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02287                    const std::lognormal_distribution<_RealType1>& __x);
02288 
02289       /**
02290        * @brief Extracts a %lognormal_distribution random number distribution
02291        * @p __x from the input stream @p __is.
02292        *
02293        * @param __is An input stream.
02294        * @param __x A %lognormal_distribution random number
02295        *            generator engine.
02296        *
02297        * @returns The input stream with @p __x extracted or in an error state.
02298        */
02299       template<typename _RealType1, typename _CharT, typename _Traits>
02300         friend std::basic_istream<_CharT, _Traits>&
02301         operator>>(std::basic_istream<_CharT, _Traits>& __is,
02302                    std::lognormal_distribution<_RealType1>& __x);
02303 
02304     private:
02305       template<typename _ForwardIterator,
02306                typename _UniformRandomNumberGenerator>
02307         void
02308         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02309                         _UniformRandomNumberGenerator& __urng,
02310                         const param_type& __p);
02311 
02312       param_type _M_param;
02313 
02314       std::normal_distribution<result_type> _M_nd;
02315     };
02316 
02317   /**
02318    * @brief Return true if two lognormal distributions are different.
02319    */
02320   template<typename _RealType>
02321     inline bool
02322     operator!=(const std::lognormal_distribution<_RealType>& __d1,
02323                const std::lognormal_distribution<_RealType>& __d2)
02324     { return !(__d1 == __d2); }
02325 
02326 
02327   /**
02328    * @brief A gamma continuous distribution for random numbers.
02329    *
02330    * The formula for the gamma probability density function is:
02331    * @f[
02332    *     p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
02333    *                         (x/\beta)^{\alpha - 1} e^{-x/\beta} 
02334    * @f]
02335    */
02336   template<typename _RealType = double>
02337     class gamma_distribution
02338     {
02339       static_assert(std::is_floating_point<_RealType>::value,
02340                     "template argument not a floating point type");
02341 
02342     public:
02343       /** The type of the range of the distribution. */
02344       typedef _RealType result_type;
02345       /** Parameter type. */
02346       struct param_type
02347       {
02348         typedef gamma_distribution<_RealType> distribution_type;
02349         friend class gamma_distribution<_RealType>;
02350 
02351         explicit
02352         param_type(_RealType __alpha_val = _RealType(1),
02353                    _RealType __beta_val = _RealType(1))
02354         : _M_alpha(__alpha_val), _M_beta(__beta_val)
02355         {
02356           _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
02357           _M_initialize();
02358         }
02359 
02360         _RealType
02361         alpha() const
02362         { return _M_alpha; }
02363 
02364         _RealType
02365         beta() const
02366         { return _M_beta; }
02367 
02368         friend bool
02369         operator==(const param_type& __p1, const param_type& __p2)
02370         { return (__p1._M_alpha == __p2._M_alpha
02371                   && __p1._M_beta == __p2._M_beta); }
02372 
02373       private:
02374         void
02375         _M_initialize();
02376 
02377         _RealType _M_alpha;
02378         _RealType _M_beta;
02379 
02380         _RealType _M_malpha, _M_a2;
02381       };
02382 
02383     public:
02384       /**
02385        * @brief Constructs a gamma distribution with parameters
02386        * @f$\alpha@f$ and @f$\beta@f$.
02387        */
02388       explicit
02389       gamma_distribution(_RealType __alpha_val = _RealType(1),
02390                          _RealType __beta_val = _RealType(1))
02391       : _M_param(__alpha_val, __beta_val), _M_nd()
02392       { }
02393 
02394       explicit
02395       gamma_distribution(const param_type& __p)
02396       : _M_param(__p), _M_nd()
02397       { }
02398 
02399       /**
02400        * @brief Resets the distribution state.
02401        */
02402       void
02403       reset()
02404       { _M_nd.reset(); }
02405 
02406       /**
02407        * @brief Returns the @f$\alpha@f$ of the distribution.
02408        */
02409       _RealType
02410       alpha() const
02411       { return _M_param.alpha(); }
02412 
02413       /**
02414        * @brief Returns the @f$\beta@f$ of the distribution.
02415        */
02416       _RealType
02417       beta() const
02418       { return _M_param.beta(); }
02419 
02420       /**
02421        * @brief Returns the parameter set of the distribution.
02422        */
02423       param_type
02424       param() const
02425       { return _M_param; }
02426 
02427       /**
02428        * @brief Sets the parameter set of the distribution.
02429        * @param __param The new parameter set of the distribution.
02430        */
02431       void
02432       param(const param_type& __param)
02433       { _M_param = __param; }
02434 
02435       /**
02436        * @brief Returns the greatest lower bound value of the distribution.
02437        */
02438       result_type
02439       min() const
02440       { return result_type(0); }
02441 
02442       /**
02443        * @brief Returns the least upper bound value of the distribution.
02444        */
02445       result_type
02446       max() const
02447       { return std::numeric_limits<result_type>::max(); }
02448 
02449       /**
02450        * @brief Generating functions.
02451        */
02452       template<typename _UniformRandomNumberGenerator>
02453         result_type
02454         operator()(_UniformRandomNumberGenerator& __urng)
02455         { return this->operator()(__urng, _M_param); }
02456 
02457       template<typename _UniformRandomNumberGenerator>
02458         result_type
02459         operator()(_UniformRandomNumberGenerator& __urng,
02460                    const param_type& __p);
02461 
02462       template<typename _ForwardIterator,
02463                typename _UniformRandomNumberGenerator>
02464         void
02465         __generate(_ForwardIterator __f, _ForwardIterator __t,
02466                    _UniformRandomNumberGenerator& __urng)
02467         { this->__generate(__f, __t, __urng, _M_param); }
02468 
02469       template<typename _ForwardIterator,
02470                typename _UniformRandomNumberGenerator>
02471         void
02472         __generate(_ForwardIterator __f, _ForwardIterator __t,
02473                    _UniformRandomNumberGenerator& __urng,
02474                    const param_type& __p)
02475         { this->__generate_impl(__f, __t, __urng, __p); }
02476 
02477       template<typename _UniformRandomNumberGenerator>
02478         void
02479         __generate(result_type* __f, result_type* __t,
02480                    _UniformRandomNumberGenerator& __urng,
02481                    const param_type& __p)
02482         { this->__generate_impl(__f, __t, __urng, __p); }
02483 
02484       /**
02485        * @brief Return true if two gamma distributions have the same
02486        *        parameters and the sequences that would be generated
02487        *        are equal.
02488        */
02489       friend bool
02490       operator==(const gamma_distribution& __d1,
02491                  const gamma_distribution& __d2)
02492       { return (__d1._M_param == __d2._M_param
02493                 && __d1._M_nd == __d2._M_nd); }
02494 
02495       /**
02496        * @brief Inserts a %gamma_distribution random number distribution
02497        * @p __x into the output stream @p __os.
02498        *
02499        * @param __os An output stream.
02500        * @param __x  A %gamma_distribution random number distribution.
02501        *
02502        * @returns The output stream with the state of @p __x inserted or in
02503        * an error state.
02504        */
02505       template<typename _RealType1, typename _CharT, typename _Traits>
02506         friend std::basic_ostream<_CharT, _Traits>&
02507         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02508                    const std::gamma_distribution<_RealType1>& __x);
02509 
02510       /**
02511        * @brief Extracts a %gamma_distribution random number distribution
02512        * @p __x from the input stream @p __is.
02513        *
02514        * @param __is An input stream.
02515        * @param __x  A %gamma_distribution random number generator engine.
02516        *
02517        * @returns The input stream with @p __x extracted or in an error state.
02518        */
02519       template<typename _RealType1, typename _CharT, typename _Traits>
02520         friend std::basic_istream<_CharT, _Traits>&
02521         operator>>(std::basic_istream<_CharT, _Traits>& __is,
02522                    std::gamma_distribution<_RealType1>& __x);
02523 
02524     private:
02525       template<typename _ForwardIterator,
02526                typename _UniformRandomNumberGenerator>
02527         void
02528         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02529                         _UniformRandomNumberGenerator& __urng,
02530                         const param_type& __p);
02531 
02532       param_type _M_param;
02533 
02534       std::normal_distribution<result_type> _M_nd;
02535     };
02536 
02537   /**
02538    * @brief Return true if two gamma distributions are different.
02539    */
02540    template<typename _RealType>
02541      inline bool
02542      operator!=(const std::gamma_distribution<_RealType>& __d1,
02543                 const std::gamma_distribution<_RealType>& __d2)
02544     { return !(__d1 == __d2); }
02545 
02546 
02547   /**
02548    * @brief A chi_squared_distribution random number distribution.
02549    *
02550    * The formula for the normal probability mass function is
02551    * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
02552    */
02553   template<typename _RealType = double>
02554     class chi_squared_distribution
02555     {
02556       static_assert(std::is_floating_point<_RealType>::value,
02557                     "template argument not a floating point type");
02558 
02559     public:
02560       /** The type of the range of the distribution. */
02561       typedef _RealType result_type;
02562       /** Parameter type. */
02563       struct param_type
02564       {
02565         typedef chi_squared_distribution<_RealType> distribution_type;
02566 
02567         explicit
02568         param_type(_RealType __n = _RealType(1))
02569         : _M_n(__n)
02570         { }
02571 
02572         _RealType
02573         n() const
02574         { return _M_n; }
02575 
02576         friend bool
02577         operator==(const param_type& __p1, const param_type& __p2)
02578         { return __p1._M_n == __p2._M_n; }
02579 
02580       private:
02581         _RealType _M_n;
02582       };
02583 
02584       explicit
02585       chi_squared_distribution(_RealType __n = _RealType(1))
02586       : _M_param(__n), _M_gd(__n / 2)
02587       { }
02588 
02589       explicit
02590       chi_squared_distribution(const param_type& __p)
02591       : _M_param(__p), _M_gd(__p.n() / 2)
02592       { }
02593 
02594       /**
02595        * @brief Resets the distribution state.
02596        */
02597       void
02598       reset()
02599       { _M_gd.reset(); }
02600 
02601       /**
02602        *
02603        */
02604       _RealType
02605       n() const
02606       { return _M_param.n(); }
02607 
02608       /**
02609        * @brief Returns the parameter set of the distribution.
02610        */
02611       param_type
02612       param() const
02613       { return _M_param; }
02614 
02615       /**
02616        * @brief Sets the parameter set of the distribution.
02617        * @param __param The new parameter set of the distribution.
02618        */
02619       void
02620       param(const param_type& __param)
02621       { _M_param = __param; }
02622 
02623       /**
02624        * @brief Returns the greatest lower bound value of the distribution.
02625        */
02626       result_type
02627       min() const
02628       { return result_type(0); }
02629 
02630       /**
02631        * @brief Returns the least upper bound value of the distribution.
02632        */
02633       result_type
02634       max() const
02635       { return std::numeric_limits<result_type>::max(); }
02636 
02637       /**
02638        * @brief Generating functions.
02639        */
02640       template<typename _UniformRandomNumberGenerator>
02641         result_type
02642         operator()(_UniformRandomNumberGenerator& __urng)
02643         { return 2 * _M_gd(__urng); }
02644 
02645       template<typename _UniformRandomNumberGenerator>
02646         result_type
02647         operator()(_UniformRandomNumberGenerator& __urng,
02648                    const param_type& __p)
02649         {
02650           typedef typename std::gamma_distribution<result_type>::param_type
02651             param_type;
02652           return 2 * _M_gd(__urng, param_type(__p.n() / 2));
02653         }
02654 
02655       template<typename _ForwardIterator,
02656                typename _UniformRandomNumberGenerator>
02657         void
02658         __generate(_ForwardIterator __f, _ForwardIterator __t,
02659                    _UniformRandomNumberGenerator& __urng)
02660         { this->__generate_impl(__f, __t, __urng); }
02661 
02662       template<typename _ForwardIterator,
02663                typename _UniformRandomNumberGenerator>
02664         void
02665         __generate(_ForwardIterator __f, _ForwardIterator __t,
02666                    _UniformRandomNumberGenerator& __urng,
02667                    const param_type& __p)
02668         { typename std::gamma_distribution<result_type>::param_type
02669             __p2(__p.n() / 2);
02670           this->__generate_impl(__f, __t, __urng, __p2); }
02671 
02672       template<typename _UniformRandomNumberGenerator>
02673         void
02674         __generate(result_type* __f, result_type* __t,
02675                    _UniformRandomNumberGenerator& __urng)
02676         { this->__generate_impl(__f, __t, __urng); }
02677 
02678       template<typename _UniformRandomNumberGenerator>
02679         void
02680         __generate(result_type* __f, result_type* __t,
02681                    _UniformRandomNumberGenerator& __urng,
02682                    const param_type& __p)
02683         { typename std::gamma_distribution<result_type>::param_type
02684             __p2(__p.n() / 2);
02685           this->__generate_impl(__f, __t, __urng, __p2); }
02686 
02687       /**
02688        * @brief Return true if two Chi-squared distributions have
02689        *        the same parameters and the sequences that would be
02690        *        generated are equal.
02691        */
02692       friend bool
02693       operator==(const chi_squared_distribution& __d1,
02694                  const chi_squared_distribution& __d2)
02695       { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
02696 
02697       /**
02698        * @brief Inserts a %chi_squared_distribution random number distribution
02699        * @p __x into the output stream @p __os.
02700        *
02701        * @param __os An output stream.
02702        * @param __x  A %chi_squared_distribution random number distribution.
02703        *
02704        * @returns The output stream with the state of @p __x inserted or in
02705        * an error state.
02706        */
02707       template<typename _RealType1, typename _CharT, typename _Traits>
02708         friend std::basic_ostream<_CharT, _Traits>&
02709         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02710                    const std::chi_squared_distribution<_RealType1>& __x);
02711 
02712       /**
02713        * @brief Extracts a %chi_squared_distribution random number distribution
02714        * @p __x from the input stream @p __is.
02715        *
02716        * @param __is An input stream.
02717        * @param __x A %chi_squared_distribution random number
02718        *            generator engine.
02719        *
02720        * @returns The input stream with @p __x extracted or in an error state.
02721        */
02722       template<typename _RealType1, typename _CharT, typename _Traits>
02723         friend std::basic_istream<_CharT, _Traits>&
02724         operator>>(std::basic_istream<_CharT, _Traits>& __is,
02725                    std::chi_squared_distribution<_RealType1>& __x);
02726 
02727     private:
02728       template<typename _ForwardIterator,
02729                typename _UniformRandomNumberGenerator>
02730         void
02731         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02732                         _UniformRandomNumberGenerator& __urng);
02733 
02734       template<typename _ForwardIterator,
02735                typename _UniformRandomNumberGenerator>
02736         void
02737         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02738                         _UniformRandomNumberGenerator& __urng,
02739                         const typename
02740                         std::gamma_distribution<result_type>::param_type& __p);
02741 
02742       param_type _M_param;
02743 
02744       std::gamma_distribution<result_type> _M_gd;
02745     };
02746 
02747   /**
02748    * @brief Return true if two Chi-squared distributions are different.
02749    */
02750   template<typename _RealType>
02751     inline bool
02752     operator!=(const std::chi_squared_distribution<_RealType>& __d1,
02753                const std::chi_squared_distribution<_RealType>& __d2)
02754     { return !(__d1 == __d2); }
02755 
02756 
02757   /**
02758    * @brief A cauchy_distribution random number distribution.
02759    *
02760    * The formula for the normal probability mass function is
02761    * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
02762    */
02763   template<typename _RealType = double>
02764     class cauchy_distribution
02765     {
02766       static_assert(std::is_floating_point<_RealType>::value,
02767                     "template argument not a floating point type");
02768 
02769     public:
02770       /** The type of the range of the distribution. */
02771       typedef _RealType result_type;
02772       /** Parameter type. */
02773       struct param_type
02774       {
02775         typedef cauchy_distribution<_RealType> distribution_type;
02776 
02777         explicit
02778         param_type(_RealType __a = _RealType(0),
02779                    _RealType __b = _RealType(1))
02780         : _M_a(__a), _M_b(__b)
02781         { }
02782 
02783         _RealType
02784         a() const
02785         { return _M_a; }
02786 
02787         _RealType
02788         b() const
02789         { return _M_b; }
02790 
02791         friend bool
02792         operator==(const param_type& __p1, const param_type& __p2)
02793         { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
02794 
02795       private:
02796         _RealType _M_a;
02797         _RealType _M_b;
02798       };
02799 
02800       explicit
02801       cauchy_distribution(_RealType __a = _RealType(0),
02802                           _RealType __b = _RealType(1))
02803       : _M_param(__a, __b)
02804       { }
02805 
02806       explicit
02807       cauchy_distribution(const param_type& __p)
02808       : _M_param(__p)
02809       { }
02810 
02811       /**
02812        * @brief Resets the distribution state.
02813        */
02814       void
02815       reset()
02816       { }
02817 
02818       /**
02819        *
02820        */
02821       _RealType
02822       a() const
02823       { return _M_param.a(); }
02824 
02825       _RealType
02826       b() const
02827       { return _M_param.b(); }
02828 
02829       /**
02830        * @brief Returns the parameter set of the distribution.
02831        */
02832       param_type
02833       param() const
02834       { return _M_param; }
02835 
02836       /**
02837        * @brief Sets the parameter set of the distribution.
02838        * @param __param The new parameter set of the distribution.
02839        */
02840       void
02841       param(const param_type& __param)
02842       { _M_param = __param; }
02843 
02844       /**
02845        * @brief Returns the greatest lower bound value of the distribution.
02846        */
02847       result_type
02848       min() const
02849       { return std::numeric_limits<result_type>::lowest(); }
02850 
02851       /**
02852        * @brief Returns the least upper bound value of the distribution.
02853        */
02854       result_type
02855       max() const
02856       { return std::numeric_limits<result_type>::max(); }
02857 
02858       /**
02859        * @brief Generating functions.
02860        */
02861       template<typename _UniformRandomNumberGenerator>
02862         result_type
02863         operator()(_UniformRandomNumberGenerator& __urng)
02864         { return this->operator()(__urng, _M_param); }
02865 
02866       template<typename _UniformRandomNumberGenerator>
02867         result_type
02868         operator()(_UniformRandomNumberGenerator& __urng,
02869                    const param_type& __p);
02870 
02871       template<typename _ForwardIterator,
02872                typename _UniformRandomNumberGenerator>
02873         void
02874         __generate(_ForwardIterator __f, _ForwardIterator __t,
02875                    _UniformRandomNumberGenerator& __urng)
02876         { this->__generate(__f, __t, __urng, _M_param); }
02877 
02878       template<typename _ForwardIterator,
02879                typename _UniformRandomNumberGenerator>
02880         void
02881         __generate(_ForwardIterator __f, _ForwardIterator __t,
02882                    _UniformRandomNumberGenerator& __urng,
02883                    const param_type& __p)
02884         { this->__generate_impl(__f, __t, __urng, __p); }
02885 
02886       template<typename _UniformRandomNumberGenerator>
02887         void
02888         __generate(result_type* __f, result_type* __t,
02889                    _UniformRandomNumberGenerator& __urng,
02890                    const param_type& __p)
02891         { this->__generate_impl(__f, __t, __urng, __p); }
02892 
02893       /**
02894        * @brief Return true if two Cauchy distributions have
02895        *        the same parameters.
02896        */
02897       friend bool
02898       operator==(const cauchy_distribution& __d1,
02899                  const cauchy_distribution& __d2)
02900       { return __d1._M_param == __d2._M_param; }
02901 
02902     private:
02903       template<typename _ForwardIterator,
02904                typename _UniformRandomNumberGenerator>
02905         void
02906         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
02907                         _UniformRandomNumberGenerator& __urng,
02908                         const param_type& __p);
02909 
02910       param_type _M_param;
02911     };
02912 
02913   /**
02914    * @brief Return true if two Cauchy distributions have
02915    *        different parameters.
02916    */
02917   template<typename _RealType>
02918     inline bool
02919     operator!=(const std::cauchy_distribution<_RealType>& __d1,
02920                const std::cauchy_distribution<_RealType>& __d2)
02921     { return !(__d1 == __d2); }
02922 
02923   /**
02924    * @brief Inserts a %cauchy_distribution random number distribution
02925    * @p __x into the output stream @p __os.
02926    *
02927    * @param __os An output stream.
02928    * @param __x  A %cauchy_distribution random number distribution.
02929    *
02930    * @returns The output stream with the state of @p __x inserted or in
02931    * an error state.
02932    */
02933   template<typename _RealType, typename _CharT, typename _Traits>
02934     std::basic_ostream<_CharT, _Traits>&
02935     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02936                const std::cauchy_distribution<_RealType>& __x);
02937 
02938   /**
02939    * @brief Extracts a %cauchy_distribution random number distribution
02940    * @p __x from the input stream @p __is.
02941    *
02942    * @param __is An input stream.
02943    * @param __x A %cauchy_distribution random number
02944    *            generator engine.
02945    *
02946    * @returns The input stream with @p __x extracted or in an error state.
02947    */
02948   template<typename _RealType, typename _CharT, typename _Traits>
02949     std::basic_istream<_CharT, _Traits>&
02950     operator>>(std::basic_istream<_CharT, _Traits>& __is,
02951                std::cauchy_distribution<_RealType>& __x);
02952 
02953 
02954   /**
02955    * @brief A fisher_f_distribution random number distribution.
02956    *
02957    * The formula for the normal probability mass function is
02958    * @f[
02959    *     p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
02960    *                (\frac{m}{n})^{m/2} x^{(m/2)-1}
02961    *                (1 + \frac{mx}{n})^{-(m+n)/2} 
02962    * @f]
02963    */
02964   template<typename _RealType = double>
02965     class fisher_f_distribution
02966     {
02967       static_assert(std::is_floating_point<_RealType>::value,
02968                     "template argument not a floating point type");
02969 
02970     public:
02971       /** The type of the range of the distribution. */
02972       typedef _RealType result_type;
02973       /** Parameter type. */
02974       struct param_type
02975       {
02976         typedef fisher_f_distribution<_RealType> distribution_type;
02977 
02978         explicit
02979         param_type(_RealType __m = _RealType(1),
02980                    _RealType __n = _RealType(1))
02981         : _M_m(__m), _M_n(__n)
02982         { }
02983 
02984         _RealType
02985         m() const
02986         { return _M_m; }
02987 
02988         _RealType
02989         n() const
02990         { return _M_n; }
02991 
02992         friend bool
02993         operator==(const param_type& __p1, const param_type& __p2)
02994         { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
02995 
02996       private:
02997         _RealType _M_m;
02998         _RealType _M_n;
02999       };
03000 
03001       explicit
03002       fisher_f_distribution(_RealType __m = _RealType(1),
03003                             _RealType __n = _RealType(1))
03004       : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
03005       { }
03006 
03007       explicit
03008       fisher_f_distribution(const param_type& __p)
03009       : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
03010       { }
03011 
03012       /**
03013        * @brief Resets the distribution state.
03014        */
03015       void
03016       reset()
03017       {
03018         _M_gd_x.reset();
03019         _M_gd_y.reset();
03020       }
03021 
03022       /**
03023        *
03024        */
03025       _RealType
03026       m() const
03027       { return _M_param.m(); }
03028 
03029       _RealType
03030       n() const
03031       { return _M_param.n(); }
03032 
03033       /**
03034        * @brief Returns the parameter set of the distribution.
03035        */
03036       param_type
03037       param() const
03038       { return _M_param; }
03039 
03040       /**
03041        * @brief Sets the parameter set of the distribution.
03042        * @param __param The new parameter set of the distribution.
03043        */
03044       void
03045       param(const param_type& __param)
03046       { _M_param = __param; }
03047 
03048       /**
03049        * @brief Returns the greatest lower bound value of the distribution.
03050        */
03051       result_type
03052       min() const
03053       { return result_type(0); }
03054 
03055       /**
03056        * @brief Returns the least upper bound value of the distribution.
03057        */
03058       result_type
03059       max() const
03060       { return std::numeric_limits<result_type>::max(); }
03061 
03062       /**
03063        * @brief Generating functions.
03064        */
03065       template<typename _UniformRandomNumberGenerator>
03066         result_type
03067         operator()(_UniformRandomNumberGenerator& __urng)
03068         { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
03069 
03070       template<typename _UniformRandomNumberGenerator>
03071         result_type
03072         operator()(_UniformRandomNumberGenerator& __urng,
03073                    const param_type& __p)
03074         {
03075           typedef typename std::gamma_distribution<result_type>::param_type
03076             param_type;
03077           return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
03078                   / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
03079         }
03080 
03081       template<typename _ForwardIterator,
03082                typename _UniformRandomNumberGenerator>
03083         void
03084         __generate(_ForwardIterator __f, _ForwardIterator __t,
03085                    _UniformRandomNumberGenerator& __urng)
03086         { this->__generate_impl(__f, __t, __urng); }
03087 
03088       template<typename _ForwardIterator,
03089                typename _UniformRandomNumberGenerator>
03090         void
03091         __generate(_ForwardIterator __f, _ForwardIterator __t,
03092                    _UniformRandomNumberGenerator& __urng,
03093                    const param_type& __p)
03094         { this->__generate_impl(__f, __t, __urng, __p); }
03095 
03096       template<typename _UniformRandomNumberGenerator>
03097         void
03098         __generate(result_type* __f, result_type* __t,
03099                    _UniformRandomNumberGenerator& __urng)
03100         { this->__generate_impl(__f, __t, __urng); }
03101 
03102       template<typename _UniformRandomNumberGenerator>
03103         void
03104         __generate(result_type* __f, result_type* __t,
03105                    _UniformRandomNumberGenerator& __urng,
03106                    const param_type& __p)
03107         { this->__generate_impl(__f, __t, __urng, __p); }
03108 
03109       /**
03110        * @brief Return true if two Fisher f distributions have
03111        *        the same parameters and the sequences that would
03112        *        be generated are equal.
03113        */
03114       friend bool
03115       operator==(const fisher_f_distribution& __d1,
03116                  const fisher_f_distribution& __d2)
03117       { return (__d1._M_param == __d2._M_param
03118                 && __d1._M_gd_x == __d2._M_gd_x
03119                 && __d1._M_gd_y == __d2._M_gd_y); }
03120 
03121       /**
03122        * @brief Inserts a %fisher_f_distribution random number distribution
03123        * @p __x into the output stream @p __os.
03124        *
03125        * @param __os An output stream.
03126        * @param __x  A %fisher_f_distribution random number distribution.
03127        *
03128        * @returns The output stream with the state of @p __x inserted or in
03129        * an error state.
03130        */
03131       template<typename _RealType1, typename _CharT, typename _Traits>
03132         friend std::basic_ostream<_CharT, _Traits>&
03133         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
03134                    const std::fisher_f_distribution<_RealType1>& __x);
03135 
03136       /**
03137        * @brief Extracts a %fisher_f_distribution random number distribution
03138        * @p __x from the input stream @p __is.
03139        *
03140        * @param __is An input stream.
03141        * @param __x A %fisher_f_distribution random number
03142        *            generator engine.
03143        *
03144        * @returns The input stream with @p __x extracted or in an error state.
03145        */
03146       template<typename _RealType1, typename _CharT, typename _Traits>
03147         friend std::basic_istream<_CharT, _Traits>&
03148         operator>>(std::basic_istream<_CharT, _Traits>& __is,
03149                    std::fisher_f_distribution<_RealType1>& __x);
03150 
03151     private:
03152       template<typename _ForwardIterator,
03153                typename _UniformRandomNumberGenerator>
03154         void
03155         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03156                         _UniformRandomNumberGenerator& __urng);
03157 
03158       template<typename _ForwardIterator,
03159                typename _UniformRandomNumberGenerator>
03160         void
03161         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03162                         _UniformRandomNumberGenerator& __urng,
03163                         const param_type& __p);
03164 
03165       param_type _M_param;
03166 
03167       std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
03168     };
03169 
03170   /**
03171    * @brief Return true if two Fisher f distributions are different.
03172    */
03173   template<typename _RealType>
03174     inline bool
03175     operator!=(const std::fisher_f_distribution<_RealType>& __d1,
03176                const std::fisher_f_distribution<_RealType>& __d2)
03177     { return !(__d1 == __d2); }
03178 
03179   /**
03180    * @brief A student_t_distribution random number distribution.
03181    *
03182    * The formula for the normal probability mass function is:
03183    * @f[
03184    *     p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
03185    *              (1 + \frac{x^2}{n}) ^{-(n+1)/2} 
03186    * @f]
03187    */
03188   template<typename _RealType = double>
03189     class student_t_distribution
03190     {
03191       static_assert(std::is_floating_point<_RealType>::value,
03192                     "template argument not a floating point type");
03193 
03194     public:
03195       /** The type of the range of the distribution. */
03196       typedef _RealType result_type;
03197       /** Parameter type. */
03198       struct param_type
03199       {
03200         typedef student_t_distribution<_RealType> distribution_type;
03201 
03202         explicit
03203         param_type(_RealType __n = _RealType(1))
03204         : _M_n(__n)
03205         { }
03206 
03207         _RealType
03208         n() const
03209         { return _M_n; }
03210 
03211         friend bool
03212         operator==(const param_type& __p1, const param_type& __p2)
03213         { return __p1._M_n == __p2._M_n; }
03214 
03215       private:
03216         _RealType _M_n;
03217       };
03218 
03219       explicit
03220       student_t_distribution(_RealType __n = _RealType(1))
03221       : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
03222       { }
03223 
03224       explicit
03225       student_t_distribution(const param_type& __p)
03226       : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
03227       { }
03228 
03229       /**
03230        * @brief Resets the distribution state.
03231        */
03232       void
03233       reset()
03234       {
03235         _M_nd.reset();
03236         _M_gd.reset();
03237       }
03238 
03239       /**
03240        *
03241        */
03242       _RealType
03243       n() const
03244       { return _M_param.n(); }
03245 
03246       /**
03247        * @brief Returns the parameter set of the distribution.
03248        */
03249       param_type
03250       param() const
03251       { return _M_param; }
03252 
03253       /**
03254        * @brief Sets the parameter set of the distribution.
03255        * @param __param The new parameter set of the distribution.
03256        */
03257       void
03258       param(const param_type& __param)
03259       { _M_param = __param; }
03260 
03261       /**
03262        * @brief Returns the greatest lower bound value of the distribution.
03263        */
03264       result_type
03265       min() const
03266       { return std::numeric_limits<result_type>::lowest(); }
03267 
03268       /**
03269        * @brief Returns the least upper bound value of the distribution.
03270        */
03271       result_type
03272       max() const
03273       { return std::numeric_limits<result_type>::max(); }
03274 
03275       /**
03276        * @brief Generating functions.
03277        */
03278       template<typename _UniformRandomNumberGenerator>
03279         result_type
03280         operator()(_UniformRandomNumberGenerator& __urng)
03281         { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
03282 
03283       template<typename _UniformRandomNumberGenerator>
03284         result_type
03285         operator()(_UniformRandomNumberGenerator& __urng,
03286                    const param_type& __p)
03287         {
03288           typedef typename std::gamma_distribution<result_type>::param_type
03289             param_type;
03290         
03291           const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
03292           return _M_nd(__urng) * std::sqrt(__p.n() / __g);
03293         }
03294 
03295       template<typename _ForwardIterator,
03296                typename _UniformRandomNumberGenerator>
03297         void
03298         __generate(_ForwardIterator __f, _ForwardIterator __t,
03299                    _UniformRandomNumberGenerator& __urng)
03300         { this->__generate_impl(__f, __t, __urng); }
03301 
03302       template<typename _ForwardIterator,
03303                typename _UniformRandomNumberGenerator>
03304         void
03305         __generate(_ForwardIterator __f, _ForwardIterator __t,
03306                    _UniformRandomNumberGenerator& __urng,
03307                    const param_type& __p)
03308         { this->__generate_impl(__f, __t, __urng, __p); }
03309 
03310       template<typename _UniformRandomNumberGenerator>
03311         void
03312         __generate(result_type* __f, result_type* __t,
03313                    _UniformRandomNumberGenerator& __urng)
03314         { this->__generate_impl(__f, __t, __urng); }
03315 
03316       template<typename _UniformRandomNumberGenerator>
03317         void
03318         __generate(result_type* __f, result_type* __t,
03319                    _UniformRandomNumberGenerator& __urng,
03320                    const param_type& __p)
03321         { this->__generate_impl(__f, __t, __urng, __p); }
03322 
03323       /**
03324        * @brief Return true if two Student t distributions have
03325        *        the same parameters and the sequences that would
03326        *        be generated are equal.
03327        */
03328       friend bool
03329       operator==(const student_t_distribution& __d1,
03330                  const student_t_distribution& __d2)
03331       { return (__d1._M_param == __d2._M_param
03332                 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
03333 
03334       /**
03335        * @brief Inserts a %student_t_distribution random number distribution
03336        * @p __x into the output stream @p __os.
03337        *
03338        * @param __os An output stream.
03339        * @param __x  A %student_t_distribution random number distribution.
03340        *
03341        * @returns The output stream with the state of @p __x inserted or in
03342        * an error state.
03343        */
03344       template<typename _RealType1, typename _CharT, typename _Traits>
03345         friend std::basic_ostream<_CharT, _Traits>&
03346         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
03347                    const std::student_t_distribution<_RealType1>& __x);
03348 
03349       /**
03350        * @brief Extracts a %student_t_distribution random number distribution
03351        * @p __x from the input stream @p __is.
03352        *
03353        * @param __is An input stream.
03354        * @param __x A %student_t_distribution random number
03355        *            generator engine.
03356        *
03357        * @returns The input stream with @p __x extracted or in an error state.
03358        */
03359       template<typename _RealType1, typename _CharT, typename _Traits>
03360         friend std::basic_istream<_CharT, _Traits>&
03361         operator>>(std::basic_istream<_CharT, _Traits>& __is,
03362                    std::student_t_distribution<_RealType1>& __x);
03363 
03364     private:
03365       template<typename _ForwardIterator,
03366                typename _UniformRandomNumberGenerator>
03367         void
03368         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03369                         _UniformRandomNumberGenerator& __urng);
03370       template<typename _ForwardIterator,
03371                typename _UniformRandomNumberGenerator>
03372         void
03373         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03374                         _UniformRandomNumberGenerator& __urng,
03375                         const param_type& __p);
03376 
03377       param_type _M_param;
03378 
03379       std::normal_distribution<result_type> _M_nd;
03380       std::gamma_distribution<result_type> _M_gd;
03381     };
03382 
03383   /**
03384    * @brief Return true if two Student t distributions are different.
03385    */
03386   template<typename _RealType>
03387     inline bool
03388     operator!=(const std::student_t_distribution<_RealType>& __d1,
03389                const std::student_t_distribution<_RealType>& __d2)
03390     { return !(__d1 == __d2); }
03391 
03392 
03393   /* @} */ // group random_distributions_normal
03394 
03395   /**
03396    * @addtogroup random_distributions_bernoulli Bernoulli Distributions
03397    * @ingroup random_distributions
03398    * @{
03399    */
03400 
03401   /**
03402    * @brief A Bernoulli random number distribution.
03403    *
03404    * Generates a sequence of true and false values with likelihood @f$p@f$
03405    * that true will come up and @f$(1 - p)@f$ that false will appear.
03406    */
03407   class bernoulli_distribution
03408   {
03409   public:
03410     /** The type of the range of the distribution. */
03411     typedef bool result_type;
03412     /** Parameter type. */
03413     struct param_type
03414     {
03415       typedef bernoulli_distribution distribution_type;
03416 
03417       explicit
03418       param_type(double __p = 0.5)
03419       : _M_p(__p)
03420       {
03421         _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
03422       }
03423 
03424       double
03425       p() const
03426       { return _M_p; }
03427 
03428       friend bool
03429       operator==(const param_type& __p1, const param_type& __p2)
03430       { return __p1._M_p == __p2._M_p; }
03431 
03432     private:
03433       double _M_p;
03434     };
03435 
03436   public:
03437     /**
03438      * @brief Constructs a Bernoulli distribution with likelihood @p p.
03439      *
03440      * @param __p  [IN]  The likelihood of a true result being returned.
03441      *                   Must be in the interval @f$[0, 1]@f$.
03442      */
03443     explicit
03444     bernoulli_distribution(double __p = 0.5)
03445     : _M_param(__p)
03446     { }
03447 
03448     explicit
03449     bernoulli_distribution(const param_type& __p)
03450     : _M_param(__p)
03451     { }
03452 
03453     /**
03454      * @brief Resets the distribution state.
03455      *
03456      * Does nothing for a Bernoulli distribution.
03457      */
03458     void
03459     reset() { }
03460 
03461     /**
03462      * @brief Returns the @p p parameter of the distribution.
03463      */
03464     double
03465     p() const
03466     { return _M_param.p(); }
03467 
03468     /**
03469      * @brief Returns the parameter set of the distribution.
03470      */
03471     param_type
03472     param() const
03473     { return _M_param; }
03474 
03475     /**
03476      * @brief Sets the parameter set of the distribution.
03477      * @param __param The new parameter set of the distribution.
03478      */
03479     void
03480     param(const param_type& __param)
03481     { _M_param = __param; }
03482 
03483     /**
03484      * @brief Returns the greatest lower bound value of the distribution.
03485      */
03486     result_type
03487     min() const
03488     { return std::numeric_limits<result_type>::min(); }
03489 
03490     /**
03491      * @brief Returns the least upper bound value of the distribution.
03492      */
03493     result_type
03494     max() const
03495     { return std::numeric_limits<result_type>::max(); }
03496 
03497     /**
03498      * @brief Generating functions.
03499      */
03500     template<typename _UniformRandomNumberGenerator>
03501       result_type
03502       operator()(_UniformRandomNumberGenerator& __urng)
03503       { return this->operator()(__urng, _M_param); }
03504 
03505     template<typename _UniformRandomNumberGenerator>
03506       result_type
03507       operator()(_UniformRandomNumberGenerator& __urng,
03508                  const param_type& __p)
03509       {
03510         __detail::_Adaptor<_UniformRandomNumberGenerator, double>
03511           __aurng(__urng);
03512         if ((__aurng() - __aurng.min())
03513              < __p.p() * (__aurng.max() - __aurng.min()))
03514           return true;
03515         return false;
03516       }
03517 
03518     template<typename _ForwardIterator,
03519              typename _UniformRandomNumberGenerator>
03520       void
03521       __generate(_ForwardIterator __f, _ForwardIterator __t,
03522                  _UniformRandomNumberGenerator& __urng)
03523       { this->__generate(__f, __t, __urng, _M_param); }
03524 
03525     template<typename _ForwardIterator,
03526              typename _UniformRandomNumberGenerator>
03527       void
03528       __generate(_ForwardIterator __f, _ForwardIterator __t,
03529                  _UniformRandomNumberGenerator& __urng, const param_type& __p)
03530       { this->__generate_impl(__f, __t, __urng, __p); }
03531 
03532     template<typename _UniformRandomNumberGenerator>
03533       void
03534       __generate(result_type* __f, result_type* __t,
03535                  _UniformRandomNumberGenerator& __urng,
03536                  const param_type& __p)
03537       { this->__generate_impl(__f, __t, __urng, __p); }
03538 
03539     /**
03540      * @brief Return true if two Bernoulli distributions have
03541      *        the same parameters.
03542      */
03543     friend bool
03544     operator==(const bernoulli_distribution& __d1,
03545                const bernoulli_distribution& __d2)
03546     { return __d1._M_param == __d2._M_param; }
03547 
03548   private:
03549     template<typename _ForwardIterator,
03550              typename _UniformRandomNumberGenerator>
03551       void
03552       __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03553                       _UniformRandomNumberGenerator& __urng,
03554                       const param_type& __p);
03555 
03556     param_type _M_param;
03557   };
03558 
03559   /**
03560    * @brief Return true if two Bernoulli distributions have
03561    *        different parameters.
03562    */
03563   inline bool
03564   operator!=(const std::bernoulli_distribution& __d1,
03565              const std::bernoulli_distribution& __d2)
03566   { return !(__d1 == __d2); }
03567 
03568   /**
03569    * @brief Inserts a %bernoulli_distribution random number distribution
03570    * @p __x into the output stream @p __os.
03571    *
03572    * @param __os An output stream.
03573    * @param __x  A %bernoulli_distribution random number distribution.
03574    *
03575    * @returns The output stream with the state of @p __x inserted or in
03576    * an error state.
03577    */
03578   template<typename _CharT, typename _Traits>
03579     std::basic_ostream<_CharT, _Traits>&
03580     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
03581                const std::bernoulli_distribution& __x);
03582 
03583   /**
03584    * @brief Extracts a %bernoulli_distribution random number distribution
03585    * @p __x from the input stream @p __is.
03586    *
03587    * @param __is An input stream.
03588    * @param __x  A %bernoulli_distribution random number generator engine.
03589    *
03590    * @returns The input stream with @p __x extracted or in an error state.
03591    */
03592   template<typename _CharT, typename _Traits>
03593     std::basic_istream<_CharT, _Traits>&
03594     operator>>(std::basic_istream<_CharT, _Traits>& __is,
03595                std::bernoulli_distribution& __x)
03596     {
03597       double __p;
03598       __is >> __p;
03599       __x.param(bernoulli_distribution::param_type(__p));
03600       return __is;
03601     }
03602 
03603 
03604   /**
03605    * @brief A discrete binomial random number distribution.
03606    *
03607    * The formula for the binomial probability density function is
03608    * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
03609    * and @f$p@f$ are the parameters of the distribution.
03610    */
03611   template<typename _IntType = int>
03612     class binomial_distribution
03613     {
03614       static_assert(std::is_integral<_IntType>::value,
03615                     "template argument not an integral type");
03616 
03617     public:
03618       /** The type of the range of the distribution. */
03619       typedef _IntType result_type;
03620       /** Parameter type. */
03621       struct param_type
03622       {
03623         typedef binomial_distribution<_IntType> distribution_type;
03624         friend class binomial_distribution<_IntType>;
03625 
03626         explicit
03627         param_type(_IntType __t = _IntType(1), double __p = 0.5)
03628         : _M_t(__t), _M_p(__p)
03629         {
03630           _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
03631                                 && (_M_p >= 0.0)
03632                                 && (_M_p <= 1.0));
03633           _M_initialize();
03634         }
03635 
03636         _IntType
03637         t() const
03638         { return _M_t; }
03639 
03640         double
03641         p() const
03642         { return _M_p; }
03643 
03644         friend bool
03645         operator==(const param_type& __p1, const param_type& __p2)
03646         { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
03647 
03648       private:
03649         void
03650         _M_initialize();
03651 
03652         _IntType _M_t;
03653         double _M_p;
03654 
03655         double _M_q;
03656 #if _GLIBCXX_USE_C99_MATH_TR1
03657         double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
03658                _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
03659 #endif
03660         bool   _M_easy;
03661       };
03662 
03663       // constructors and member function
03664       explicit
03665       binomial_distribution(_IntType __t = _IntType(1),
03666                             double __p = 0.5)
03667       : _M_param(__t, __p), _M_nd()
03668       { }
03669 
03670       explicit
03671       binomial_distribution(const param_type& __p)
03672       : _M_param(__p), _M_nd()
03673       { }
03674 
03675       /**
03676        * @brief Resets the distribution state.
03677        */
03678       void
03679       reset()
03680       { _M_nd.reset(); }
03681 
03682       /**
03683        * @brief Returns the distribution @p t parameter.
03684        */
03685       _IntType
03686       t() const
03687       { return _M_param.t(); }
03688 
03689       /**
03690        * @brief Returns the distribution @p p parameter.
03691        */
03692       double
03693       p() const
03694       { return _M_param.p(); }
03695 
03696       /**
03697        * @brief Returns the parameter set of the distribution.
03698        */
03699       param_type
03700       param() const
03701       { return _M_param; }
03702 
03703       /**
03704        * @brief Sets the parameter set of the distribution.
03705        * @param __param The new parameter set of the distribution.
03706        */
03707       void
03708       param(const param_type& __param)
03709       { _M_param = __param; }
03710 
03711       /**
03712        * @brief Returns the greatest lower bound value of the distribution.
03713        */
03714       result_type
03715       min() const
03716       { return 0; }
03717 
03718       /**
03719        * @brief Returns the least upper bound value of the distribution.
03720        */
03721       result_type
03722       max() const
03723       { return _M_param.t(); }
03724 
03725       /**
03726        * @brief Generating functions.
03727        */
03728       template<typename _UniformRandomNumberGenerator>
03729         result_type
03730         operator()(_UniformRandomNumberGenerator& __urng)
03731         { return this->operator()(__urng, _M_param); }
03732 
03733       template<typename _UniformRandomNumberGenerator>
03734         result_type
03735         operator()(_UniformRandomNumberGenerator& __urng,
03736                    const param_type& __p);
03737 
03738       template<typename _ForwardIterator,
03739                typename _UniformRandomNumberGenerator>
03740         void
03741         __generate(_ForwardIterator __f, _ForwardIterator __t,
03742                    _UniformRandomNumberGenerator& __urng)
03743         { this->__generate(__f, __t, __urng, _M_param); }
03744 
03745       template<typename _ForwardIterator,
03746                typename _UniformRandomNumberGenerator>
03747         void
03748         __generate(_ForwardIterator __f, _ForwardIterator __t,
03749                    _UniformRandomNumberGenerator& __urng,
03750                    const param_type& __p)
03751         { this->__generate_impl(__f, __t, __urng, __p); }
03752 
03753       template<typename _UniformRandomNumberGenerator>
03754         void
03755         __generate(result_type* __f, result_type* __t,
03756                    _UniformRandomNumberGenerator& __urng,
03757                    const param_type& __p)
03758         { this->__generate_impl(__f, __t, __urng, __p); }
03759 
03760       /**
03761        * @brief Return true if two binomial distributions have
03762        *        the same parameters and the sequences that would
03763        *        be generated are equal.
03764        */
03765         friend bool
03766         operator==(const binomial_distribution& __d1,
03767                    const binomial_distribution& __d2)
03768 #ifdef _GLIBCXX_USE_C99_MATH_TR1
03769         { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
03770 #else
03771         { return __d1._M_param == __d2._M_param; }
03772 #endif
03773 
03774       /**
03775        * @brief Inserts a %binomial_distribution random number distribution
03776        * @p __x into the output stream @p __os.
03777        *
03778        * @param __os An output stream.
03779        * @param __x  A %binomial_distribution random number distribution.
03780        *
03781        * @returns The output stream with the state of @p __x inserted or in
03782        * an error state.
03783        */
03784       template<typename _IntType1,
03785                typename _CharT, typename _Traits>
03786         friend std::basic_ostream<_CharT, _Traits>&
03787         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
03788                    const std::binomial_distribution<_IntType1>& __x);
03789 
03790       /**
03791        * @brief Extracts a %binomial_distribution random number distribution
03792        * @p __x from the input stream @p __is.
03793        *
03794        * @param __is An input stream.
03795        * @param __x  A %binomial_distribution random number generator engine.
03796        *
03797        * @returns The input stream with @p __x extracted or in an error
03798        *          state.
03799        */
03800       template<typename _IntType1,
03801                typename _CharT, typename _Traits>
03802         friend std::basic_istream<_CharT, _Traits>&
03803         operator>>(std::basic_istream<_CharT, _Traits>& __is,
03804                    std::binomial_distribution<_IntType1>& __x);
03805 
03806     private:
03807       template<typename _ForwardIterator,
03808                typename _UniformRandomNumberGenerator>
03809         void
03810         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03811                         _UniformRandomNumberGenerator& __urng,
03812                         const param_type& __p);
03813 
03814       template<typename _UniformRandomNumberGenerator>
03815         result_type
03816         _M_waiting(_UniformRandomNumberGenerator& __urng,
03817                    _IntType __t, double __q);
03818 
03819       param_type _M_param;
03820 
03821       // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
03822       std::normal_distribution<double> _M_nd;
03823     };
03824 
03825   /**
03826    * @brief Return true if two binomial distributions are different.
03827    */
03828   template<typename _IntType>
03829     inline bool
03830     operator!=(const std::binomial_distribution<_IntType>& __d1,
03831                const std::binomial_distribution<_IntType>& __d2)
03832     { return !(__d1 == __d2); }
03833 
03834 
03835   /**
03836    * @brief A discrete geometric random number distribution.
03837    *
03838    * The formula for the geometric probability density function is
03839    * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
03840    * distribution.
03841    */
03842   template<typename _IntType = int>
03843     class geometric_distribution
03844     {
03845       static_assert(std::is_integral<_IntType>::value,
03846                     "template argument not an integral type");
03847 
03848     public:
03849       /** The type of the range of the distribution. */
03850       typedef _IntType  result_type;
03851       /** Parameter type. */
03852       struct param_type
03853       {
03854         typedef geometric_distribution<_IntType> distribution_type;
03855         friend class geometric_distribution<_IntType>;
03856 
03857         explicit
03858         param_type(double __p = 0.5)
03859         : _M_p(__p)
03860         {
03861           _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
03862           _M_initialize();
03863         }
03864 
03865         double
03866         p() const
03867         { return _M_p; }
03868 
03869         friend bool
03870         operator==(const param_type& __p1, const param_type& __p2)
03871         { return __p1._M_p == __p2._M_p; }
03872 
03873       private:
03874         void
03875         _M_initialize()
03876         { _M_log_1_p = std::log(1.0 - _M_p); }
03877 
03878         double _M_p;
03879 
03880         double _M_log_1_p;
03881       };
03882 
03883       // constructors and member function
03884       explicit
03885       geometric_distribution(double __p = 0.5)
03886       : _M_param(__p)
03887       { }
03888 
03889       explicit
03890       geometric_distribution(const param_type& __p)
03891       : _M_param(__p)
03892       { }
03893 
03894       /**
03895        * @brief Resets the distribution state.
03896        *
03897        * Does nothing for the geometric distribution.
03898        */
03899       void
03900       reset() { }
03901 
03902       /**
03903        * @brief Returns the distribution parameter @p p.
03904        */
03905       double
03906       p() const
03907       { return _M_param.p(); }
03908 
03909       /**
03910        * @brief Returns the parameter set of the distribution.
03911        */
03912       param_type
03913       param() const
03914       { return _M_param; }
03915 
03916       /**
03917        * @brief Sets the parameter set of the distribution.
03918        * @param __param The new parameter set of the distribution.
03919        */
03920       void
03921       param(const param_type& __param)
03922       { _M_param = __param; }
03923 
03924       /**
03925        * @brief Returns the greatest lower bound value of the distribution.
03926        */
03927       result_type
03928       min() const
03929       { return 0; }
03930 
03931       /**
03932        * @brief Returns the least upper bound value of the distribution.
03933        */
03934       result_type
03935       max() const
03936       { return std::numeric_limits<result_type>::max(); }
03937 
03938       /**
03939        * @brief Generating functions.
03940        */
03941       template<typename _UniformRandomNumberGenerator>
03942         result_type
03943         operator()(_UniformRandomNumberGenerator& __urng)
03944         { return this->operator()(__urng, _M_param); }
03945 
03946       template<typename _UniformRandomNumberGenerator>
03947         result_type
03948         operator()(_UniformRandomNumberGenerator& __urng,
03949                    const param_type& __p);
03950 
03951       template<typename _ForwardIterator,
03952                typename _UniformRandomNumberGenerator>
03953         void
03954         __generate(_ForwardIterator __f, _ForwardIterator __t,
03955                    _UniformRandomNumberGenerator& __urng)
03956         { this->__generate(__f, __t, __urng, _M_param); }
03957 
03958       template<typename _ForwardIterator,
03959                typename _UniformRandomNumberGenerator>
03960         void
03961         __generate(_ForwardIterator __f, _ForwardIterator __t,
03962                    _UniformRandomNumberGenerator& __urng,
03963                    const param_type& __p)
03964         { this->__generate_impl(__f, __t, __urng, __p); }
03965 
03966       template<typename _UniformRandomNumberGenerator>
03967         void
03968         __generate(result_type* __f, result_type* __t,
03969                    _UniformRandomNumberGenerator& __urng,
03970                    const param_type& __p)
03971         { this->__generate_impl(__f, __t, __urng, __p); }
03972 
03973       /**
03974        * @brief Return true if two geometric distributions have
03975        *        the same parameters.
03976        */
03977       friend bool
03978       operator==(const geometric_distribution& __d1,
03979                  const geometric_distribution& __d2)
03980       { return __d1._M_param == __d2._M_param; }
03981 
03982     private:
03983       template<typename _ForwardIterator,
03984                typename _UniformRandomNumberGenerator>
03985         void
03986         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
03987                         _UniformRandomNumberGenerator& __urng,
03988                         const param_type& __p);
03989 
03990       param_type _M_param;
03991     };
03992 
03993   /**
03994    * @brief Return true if two geometric distributions have
03995    *        different parameters.
03996    */
03997   template<typename _IntType>
03998     inline bool
03999     operator!=(const std::geometric_distribution<_IntType>& __d1,
04000                const std::geometric_distribution<_IntType>& __d2)
04001     { return !(__d1 == __d2); }
04002 
04003   /**
04004    * @brief Inserts a %geometric_distribution random number distribution
04005    * @p __x into the output stream @p __os.
04006    *
04007    * @param __os An output stream.
04008    * @param __x  A %geometric_distribution random number distribution.
04009    *
04010    * @returns The output stream with the state of @p __x inserted or in
04011    * an error state.
04012    */
04013   template<typename _IntType,
04014            typename _CharT, typename _Traits>
04015     std::basic_ostream<_CharT, _Traits>&
04016     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04017                const std::geometric_distribution<_IntType>& __x);
04018 
04019   /**
04020    * @brief Extracts a %geometric_distribution random number distribution
04021    * @p __x from the input stream @p __is.
04022    *
04023    * @param __is An input stream.
04024    * @param __x  A %geometric_distribution random number generator engine.
04025    *
04026    * @returns The input stream with @p __x extracted or in an error state.
04027    */
04028   template<typename _IntType,
04029            typename _CharT, typename _Traits>
04030     std::basic_istream<_CharT, _Traits>&
04031     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04032                std::geometric_distribution<_IntType>& __x);
04033 
04034 
04035   /**
04036    * @brief A negative_binomial_distribution random number distribution.
04037    *
04038    * The formula for the negative binomial probability mass function is
04039    * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
04040    * and @f$p@f$ are the parameters of the distribution.
04041    */
04042   template<typename _IntType = int>
04043     class negative_binomial_distribution
04044     {
04045       static_assert(std::is_integral<_IntType>::value,
04046                     "template argument not an integral type");
04047 
04048     public:
04049       /** The type of the range of the distribution. */
04050       typedef _IntType result_type;
04051       /** Parameter type. */
04052       struct param_type
04053       {
04054         typedef negative_binomial_distribution<_IntType> distribution_type;
04055 
04056         explicit
04057         param_type(_IntType __k = 1, double __p = 0.5)
04058         : _M_k(__k), _M_p(__p)
04059         {
04060           _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
04061         }
04062 
04063         _IntType
04064         k() const
04065         { return _M_k; }
04066 
04067         double
04068         p() const
04069         { return _M_p; }
04070 
04071         friend bool
04072         operator==(const param_type& __p1, const param_type& __p2)
04073         { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
04074 
04075       private:
04076         _IntType _M_k;
04077         double _M_p;
04078       };
04079 
04080       explicit
04081       negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
04082       : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
04083       { }
04084 
04085       explicit
04086       negative_binomial_distribution(const param_type& __p)
04087       : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
04088       { }
04089 
04090       /**
04091        * @brief Resets the distribution state.
04092        */
04093       void
04094       reset()
04095       { _M_gd.reset(); }
04096 
04097       /**
04098        * @brief Return the @f$k@f$ parameter of the distribution.
04099        */
04100       _IntType
04101       k() const
04102       { return _M_param.k(); }
04103 
04104       /**
04105        * @brief Return the @f$p@f$ parameter of the distribution.
04106        */
04107       double
04108       p() const
04109       { return _M_param.p(); }
04110 
04111       /**
04112        * @brief Returns the parameter set of the distribution.
04113        */
04114       param_type
04115       param() const
04116       { return _M_param; }
04117 
04118       /**
04119        * @brief Sets the parameter set of the distribution.
04120        * @param __param The new parameter set of the distribution.
04121        */
04122       void
04123       param(const param_type& __param)
04124       { _M_param = __param; }
04125 
04126       /**
04127        * @brief Returns the greatest lower bound value of the distribution.
04128        */
04129       result_type
04130       min() const
04131       { return result_type(0); }
04132 
04133       /**
04134        * @brief Returns the least upper bound value of the distribution.
04135        */
04136       result_type
04137       max() const
04138       { return std::numeric_limits<result_type>::max(); }
04139 
04140       /**
04141        * @brief Generating functions.
04142        */
04143       template<typename _UniformRandomNumberGenerator>
04144         result_type
04145         operator()(_UniformRandomNumberGenerator& __urng);
04146 
04147       template<typename _UniformRandomNumberGenerator>
04148         result_type
04149         operator()(_UniformRandomNumberGenerator& __urng,
04150                    const param_type& __p);
04151 
04152       template<typename _ForwardIterator,
04153                typename _UniformRandomNumberGenerator>
04154         void
04155         __generate(_ForwardIterator __f, _ForwardIterator __t,
04156                    _UniformRandomNumberGenerator& __urng)
04157         { this->__generate_impl(__f, __t, __urng); }
04158 
04159       template<typename _ForwardIterator,
04160                typename _UniformRandomNumberGenerator>
04161         void
04162         __generate(_ForwardIterator __f, _ForwardIterator __t,
04163                    _UniformRandomNumberGenerator& __urng,
04164                    const param_type& __p)
04165         { this->__generate_impl(__f, __t, __urng, __p); }
04166 
04167       template<typename _UniformRandomNumberGenerator>
04168         void
04169         __generate(result_type* __f, result_type* __t,
04170                    _UniformRandomNumberGenerator& __urng)
04171         { this->__generate_impl(__f, __t, __urng); }
04172 
04173       template<typename _UniformRandomNumberGenerator>
04174         void
04175         __generate(result_type* __f, result_type* __t,
04176                    _UniformRandomNumberGenerator& __urng,
04177                    const param_type& __p)
04178         { this->__generate_impl(__f, __t, __urng, __p); }
04179 
04180       /**
04181        * @brief Return true if two negative binomial distributions have
04182        *        the same parameters and the sequences that would be
04183        *        generated are equal.
04184        */
04185       friend bool
04186       operator==(const negative_binomial_distribution& __d1,
04187                  const negative_binomial_distribution& __d2)
04188       { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
04189 
04190       /**
04191        * @brief Inserts a %negative_binomial_distribution random
04192        *        number distribution @p __x into the output stream @p __os.
04193        *
04194        * @param __os An output stream.
04195        * @param __x  A %negative_binomial_distribution random number
04196        *             distribution.
04197        *
04198        * @returns The output stream with the state of @p __x inserted or in
04199        *          an error state.
04200        */
04201       template<typename _IntType1, typename _CharT, typename _Traits>
04202         friend std::basic_ostream<_CharT, _Traits>&
04203         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04204                    const std::negative_binomial_distribution<_IntType1>& __x);
04205 
04206       /**
04207        * @brief Extracts a %negative_binomial_distribution random number
04208        *        distribution @p __x from the input stream @p __is.
04209        *
04210        * @param __is An input stream.
04211        * @param __x A %negative_binomial_distribution random number
04212        *            generator engine.
04213        *
04214        * @returns The input stream with @p __x extracted or in an error state.
04215        */
04216       template<typename _IntType1, typename _CharT, typename _Traits>
04217         friend std::basic_istream<_CharT, _Traits>&
04218         operator>>(std::basic_istream<_CharT, _Traits>& __is,
04219                    std::negative_binomial_distribution<_IntType1>& __x);
04220 
04221     private:
04222       template<typename _ForwardIterator,
04223                typename _UniformRandomNumberGenerator>
04224         void
04225         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04226                         _UniformRandomNumberGenerator& __urng);
04227       template<typename _ForwardIterator,
04228                typename _UniformRandomNumberGenerator>
04229         void
04230         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04231                         _UniformRandomNumberGenerator& __urng,
04232                         const param_type& __p);
04233 
04234       param_type _M_param;
04235 
04236       std::gamma_distribution<double> _M_gd;
04237     };
04238 
04239   /**
04240    * @brief Return true if two negative binomial distributions are different.
04241    */
04242   template<typename _IntType>
04243     inline bool
04244     operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
04245                const std::negative_binomial_distribution<_IntType>& __d2)
04246     { return !(__d1 == __d2); }
04247 
04248 
04249   /* @} */ // group random_distributions_bernoulli
04250 
04251   /**
04252    * @addtogroup random_distributions_poisson Poisson Distributions
04253    * @ingroup random_distributions
04254    * @{
04255    */
04256 
04257   /**
04258    * @brief A discrete Poisson random number distribution.
04259    *
04260    * The formula for the Poisson probability density function is
04261    * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
04262    * parameter of the distribution.
04263    */
04264   template<typename _IntType = int>
04265     class poisson_distribution
04266     {
04267       static_assert(std::is_integral<_IntType>::value,
04268                     "template argument not an integral type");
04269 
04270     public:
04271       /** The type of the range of the distribution. */
04272       typedef _IntType  result_type;
04273       /** Parameter type. */
04274       struct param_type
04275       {
04276         typedef poisson_distribution<_IntType> distribution_type;
04277         friend class poisson_distribution<_IntType>;
04278 
04279         explicit
04280         param_type(double __mean = 1.0)
04281         : _M_mean(__mean)
04282         {
04283           _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
04284           _M_initialize();
04285         }
04286 
04287         double
04288         mean() const
04289         { return _M_mean; }
04290 
04291         friend bool
04292         operator==(const param_type& __p1, const param_type& __p2)
04293         { return __p1._M_mean == __p2._M_mean; }
04294 
04295       private:
04296         // Hosts either log(mean) or the threshold of the simple method.
04297         void
04298         _M_initialize();
04299 
04300         double _M_mean;
04301 
04302         double _M_lm_thr;
04303 #if _GLIBCXX_USE_C99_MATH_TR1
04304         double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
04305 #endif
04306       };
04307 
04308       // constructors and member function
04309       explicit
04310       poisson_distribution(double __mean = 1.0)
04311       : _M_param(__mean), _M_nd()
04312       { }
04313 
04314       explicit
04315       poisson_distribution(const param_type& __p)
04316       : _M_param(__p), _M_nd()
04317       { }
04318 
04319       /**
04320        * @brief Resets the distribution state.
04321        */
04322       void
04323       reset()
04324       { _M_nd.reset(); }
04325 
04326       /**
04327        * @brief Returns the distribution parameter @p mean.
04328        */
04329       double
04330       mean() const
04331       { return _M_param.mean(); }
04332 
04333       /**
04334        * @brief Returns the parameter set of the distribution.
04335        */
04336       param_type
04337       param() const
04338       { return _M_param; }
04339 
04340       /**
04341        * @brief Sets the parameter set of the distribution.
04342        * @param __param The new parameter set of the distribution.
04343        */
04344       void
04345       param(const param_type& __param)
04346       { _M_param = __param; }
04347 
04348       /**
04349        * @brief Returns the greatest lower bound value of the distribution.
04350        */
04351       result_type
04352       min() const
04353       { return 0; }
04354 
04355       /**
04356        * @brief Returns the least upper bound value of the distribution.
04357        */
04358       result_type
04359       max() const
04360       { return std::numeric_limits<result_type>::max(); }
04361 
04362       /**
04363        * @brief Generating functions.
04364        */
04365       template<typename _UniformRandomNumberGenerator>
04366         result_type
04367         operator()(_UniformRandomNumberGenerator& __urng)
04368         { return this->operator()(__urng, _M_param); }
04369 
04370       template<typename _UniformRandomNumberGenerator>
04371         result_type
04372         operator()(_UniformRandomNumberGenerator& __urng,
04373                    const param_type& __p);
04374 
04375       template<typename _ForwardIterator,
04376                typename _UniformRandomNumberGenerator>
04377         void
04378         __generate(_ForwardIterator __f, _ForwardIterator __t,
04379                    _UniformRandomNumberGenerator& __urng)
04380         { this->__generate(__f, __t, __urng, _M_param); }
04381 
04382       template<typename _ForwardIterator,
04383                typename _UniformRandomNumberGenerator>
04384         void
04385         __generate(_ForwardIterator __f, _ForwardIterator __t,
04386                    _UniformRandomNumberGenerator& __urng,
04387                    const param_type& __p)
04388         { this->__generate_impl(__f, __t, __urng, __p); }
04389 
04390       template<typename _UniformRandomNumberGenerator>
04391         void
04392         __generate(result_type* __f, result_type* __t,
04393                    _UniformRandomNumberGenerator& __urng,
04394                    const param_type& __p)
04395         { this->__generate_impl(__f, __t, __urng, __p); }
04396 
04397        /**
04398         * @brief Return true if two Poisson distributions have the same
04399         *        parameters and the sequences that would be generated
04400         *        are equal.
04401         */
04402       friend bool
04403       operator==(const poisson_distribution& __d1,
04404                  const poisson_distribution& __d2)
04405 #ifdef _GLIBCXX_USE_C99_MATH_TR1
04406       { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
04407 #else
04408       { return __d1._M_param == __d2._M_param; }
04409 #endif
04410 
04411       /**
04412        * @brief Inserts a %poisson_distribution random number distribution
04413        * @p __x into the output stream @p __os.
04414        *
04415        * @param __os An output stream.
04416        * @param __x  A %poisson_distribution random number distribution.
04417        *
04418        * @returns The output stream with the state of @p __x inserted or in
04419        * an error state.
04420        */
04421       template<typename _IntType1, typename _CharT, typename _Traits>
04422         friend std::basic_ostream<_CharT, _Traits>&
04423         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04424                    const std::poisson_distribution<_IntType1>& __x);
04425 
04426       /**
04427        * @brief Extracts a %poisson_distribution random number distribution
04428        * @p __x from the input stream @p __is.
04429        *
04430        * @param __is An input stream.
04431        * @param __x  A %poisson_distribution random number generator engine.
04432        *
04433        * @returns The input stream with @p __x extracted or in an error
04434        *          state.
04435        */
04436       template<typename _IntType1, typename _CharT, typename _Traits>
04437         friend std::basic_istream<_CharT, _Traits>&
04438         operator>>(std::basic_istream<_CharT, _Traits>& __is,
04439                    std::poisson_distribution<_IntType1>& __x);
04440 
04441     private:
04442       template<typename _ForwardIterator,
04443                typename _UniformRandomNumberGenerator>
04444         void
04445         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04446                         _UniformRandomNumberGenerator& __urng,
04447                         const param_type& __p);
04448 
04449       param_type _M_param;
04450 
04451       // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
04452       std::normal_distribution<double> _M_nd;
04453     };
04454 
04455   /**
04456    * @brief Return true if two Poisson distributions are different.
04457    */
04458   template<typename _IntType>
04459     inline bool
04460     operator!=(const std::poisson_distribution<_IntType>& __d1,
04461                const std::poisson_distribution<_IntType>& __d2)
04462     { return !(__d1 == __d2); }
04463 
04464 
04465   /**
04466    * @brief An exponential continuous distribution for random numbers.
04467    *
04468    * The formula for the exponential probability density function is
04469    * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
04470    *
04471    * <table border=1 cellpadding=10 cellspacing=0>
04472    * <caption align=top>Distribution Statistics</caption>
04473    * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
04474    * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
04475    * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
04476    * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
04477    * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
04478    * </table>
04479    */
04480   template<typename _RealType = double>
04481     class exponential_distribution
04482     {
04483       static_assert(std::is_floating_point<_RealType>::value,
04484                     "template argument not a floating point type");
04485 
04486     public:
04487       /** The type of the range of the distribution. */
04488       typedef _RealType result_type;
04489       /** Parameter type. */
04490       struct param_type
04491       {
04492         typedef exponential_distribution<_RealType> distribution_type;
04493 
04494         explicit
04495         param_type(_RealType __lambda = _RealType(1))
04496         : _M_lambda(__lambda)
04497         {
04498           _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
04499         }
04500 
04501         _RealType
04502         lambda() const
04503         { return _M_lambda; }
04504 
04505         friend bool
04506         operator==(const param_type& __p1, const param_type& __p2)
04507         { return __p1._M_lambda == __p2._M_lambda; }
04508 
04509       private:
04510         _RealType _M_lambda;
04511       };
04512 
04513     public:
04514       /**
04515        * @brief Constructs an exponential distribution with inverse scale
04516        *        parameter @f$\lambda@f$.
04517        */
04518       explicit
04519       exponential_distribution(const result_type& __lambda = result_type(1))
04520       : _M_param(__lambda)
04521       { }
04522 
04523       explicit
04524       exponential_distribution(const param_type& __p)
04525       : _M_param(__p)
04526       { }
04527 
04528       /**
04529        * @brief Resets the distribution state.
04530        *
04531        * Has no effect on exponential distributions.
04532        */
04533       void
04534       reset() { }
04535 
04536       /**
04537        * @brief Returns the inverse scale parameter of the distribution.
04538        */
04539       _RealType
04540       lambda() const
04541       { return _M_param.lambda(); }
04542 
04543       /**
04544        * @brief Returns the parameter set of the distribution.
04545        */
04546       param_type
04547       param() const
04548       { return _M_param; }
04549 
04550       /**
04551        * @brief Sets the parameter set of the distribution.
04552        * @param __param The new parameter set of the distribution.
04553        */
04554       void
04555       param(const param_type& __param)
04556       { _M_param = __param; }
04557 
04558       /**
04559        * @brief Returns the greatest lower bound value of the distribution.
04560        */
04561       result_type
04562       min() const
04563       { return result_type(0); }
04564 
04565       /**
04566        * @brief Returns the least upper bound value of the distribution.
04567        */
04568       result_type
04569       max() const
04570       { return std::numeric_limits<result_type>::max(); }
04571 
04572       /**
04573        * @brief Generating functions.
04574        */
04575       template<typename _UniformRandomNumberGenerator>
04576         result_type
04577         operator()(_UniformRandomNumberGenerator& __urng)
04578         { return this->operator()(__urng, _M_param); }
04579 
04580       template<typename _UniformRandomNumberGenerator>
04581         result_type
04582         operator()(_UniformRandomNumberGenerator& __urng,
04583                    const param_type& __p)
04584         {
04585           __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
04586             __aurng(__urng);
04587           return -std::log(result_type(1) - __aurng()) / __p.lambda();
04588         }
04589 
04590       template<typename _ForwardIterator,
04591                typename _UniformRandomNumberGenerator>
04592         void
04593         __generate(_ForwardIterator __f, _ForwardIterator __t,
04594                    _UniformRandomNumberGenerator& __urng)
04595         { this->__generate(__f, __t, __urng, _M_param); }
04596 
04597       template<typename _ForwardIterator,
04598                typename _UniformRandomNumberGenerator>
04599         void
04600         __generate(_ForwardIterator __f, _ForwardIterator __t,
04601                    _UniformRandomNumberGenerator& __urng,
04602                    const param_type& __p)
04603         { this->__generate_impl(__f, __t, __urng, __p); }
04604 
04605       template<typename _UniformRandomNumberGenerator>
04606         void
04607         __generate(result_type* __f, result_type* __t,
04608                    _UniformRandomNumberGenerator& __urng,
04609                    const param_type& __p)
04610         { this->__generate_impl(__f, __t, __urng, __p); }
04611 
04612       /**
04613        * @brief Return true if two exponential distributions have the same
04614        *        parameters.
04615        */
04616       friend bool
04617       operator==(const exponential_distribution& __d1,
04618                  const exponential_distribution& __d2)
04619       { return __d1._M_param == __d2._M_param; }
04620 
04621     private:
04622       template<typename _ForwardIterator,
04623                typename _UniformRandomNumberGenerator>
04624         void
04625         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04626                         _UniformRandomNumberGenerator& __urng,
04627                         const param_type& __p);
04628 
04629       param_type _M_param;
04630     };
04631 
04632   /**
04633    * @brief Return true if two exponential distributions have different
04634    *        parameters.
04635    */
04636   template<typename _RealType>
04637     inline bool
04638     operator!=(const std::exponential_distribution<_RealType>& __d1,
04639                const std::exponential_distribution<_RealType>& __d2)
04640     { return !(__d1 == __d2); }
04641 
04642   /**
04643    * @brief Inserts a %exponential_distribution random number distribution
04644    * @p __x into the output stream @p __os.
04645    *
04646    * @param __os An output stream.
04647    * @param __x  A %exponential_distribution random number distribution.
04648    *
04649    * @returns The output stream with the state of @p __x inserted or in
04650    * an error state.
04651    */
04652   template<typename _RealType, typename _CharT, typename _Traits>
04653     std::basic_ostream<_CharT, _Traits>&
04654     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04655                const std::exponential_distribution<_RealType>& __x);
04656 
04657   /**
04658    * @brief Extracts a %exponential_distribution random number distribution
04659    * @p __x from the input stream @p __is.
04660    *
04661    * @param __is An input stream.
04662    * @param __x A %exponential_distribution random number
04663    *            generator engine.
04664    *
04665    * @returns The input stream with @p __x extracted or in an error state.
04666    */
04667   template<typename _RealType, typename _CharT, typename _Traits>
04668     std::basic_istream<_CharT, _Traits>&
04669     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04670                std::exponential_distribution<_RealType>& __x);
04671 
04672 
04673   /**
04674    * @brief A weibull_distribution random number distribution.
04675    *
04676    * The formula for the normal probability density function is:
04677    * @f[
04678    *     p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
04679    *                         \exp{(-(\frac{x}{\beta})^\alpha)} 
04680    * @f]
04681    */
04682   template<typename _RealType = double>
04683     class weibull_distribution
04684     {
04685       static_assert(std::is_floating_point<_RealType>::value,
04686                     "template argument not a floating point type");
04687 
04688     public:
04689       /** The type of the range of the distribution. */
04690       typedef _RealType result_type;
04691       /** Parameter type. */
04692       struct param_type
04693       {
04694         typedef weibull_distribution<_RealType> distribution_type;
04695 
04696         explicit
04697         param_type(_RealType __a = _RealType(1),
04698                    _RealType __b = _RealType(1))
04699         : _M_a(__a), _M_b(__b)
04700         { }
04701 
04702         _RealType
04703         a() const
04704         { return _M_a; }
04705 
04706         _RealType
04707         b() const
04708         { return _M_b; }
04709 
04710         friend bool
04711         operator==(const param_type& __p1, const param_type& __p2)
04712         { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
04713 
04714       private:
04715         _RealType _M_a;
04716         _RealType _M_b;
04717       };
04718 
04719       explicit
04720       weibull_distribution(_RealType __a = _RealType(1),
04721                            _RealType __b = _RealType(1))
04722       : _M_param(__a, __b)
04723       { }
04724 
04725       explicit
04726       weibull_distribution(const param_type& __p)
04727       : _M_param(__p)
04728       { }
04729 
04730       /**
04731        * @brief Resets the distribution state.
04732        */
04733       void
04734       reset()
04735       { }
04736 
04737       /**
04738        * @brief Return the @f$a@f$ parameter of the distribution.
04739        */
04740       _RealType
04741       a() const
04742       { return _M_param.a(); }
04743 
04744       /**
04745        * @brief Return the @f$b@f$ parameter of the distribution.
04746        */
04747       _RealType
04748       b() const
04749       { return _M_param.b(); }
04750 
04751       /**
04752        * @brief Returns the parameter set of the distribution.
04753        */
04754       param_type
04755       param() const
04756       { return _M_param; }
04757 
04758       /**
04759        * @brief Sets the parameter set of the distribution.
04760        * @param __param The new parameter set of the distribution.
04761        */
04762       void
04763       param(const param_type& __param)
04764       { _M_param = __param; }
04765 
04766       /**
04767        * @brief Returns the greatest lower bound value of the distribution.
04768        */
04769       result_type
04770       min() const
04771       { return result_type(0); }
04772 
04773       /**
04774        * @brief Returns the least upper bound value of the distribution.
04775        */
04776       result_type
04777       max() const
04778       { return std::numeric_limits<result_type>::max(); }
04779 
04780       /**
04781        * @brief Generating functions.
04782        */
04783       template<typename _UniformRandomNumberGenerator>
04784         result_type
04785         operator()(_UniformRandomNumberGenerator& __urng)
04786         { return this->operator()(__urng, _M_param); }
04787 
04788       template<typename _UniformRandomNumberGenerator>
04789         result_type
04790         operator()(_UniformRandomNumberGenerator& __urng,
04791                    const param_type& __p);
04792 
04793       template<typename _ForwardIterator,
04794                typename _UniformRandomNumberGenerator>
04795         void
04796         __generate(_ForwardIterator __f, _ForwardIterator __t,
04797                    _UniformRandomNumberGenerator& __urng)
04798         { this->__generate(__f, __t, __urng, _M_param); }
04799 
04800       template<typename _ForwardIterator,
04801                typename _UniformRandomNumberGenerator>
04802         void
04803         __generate(_ForwardIterator __f, _ForwardIterator __t,
04804                    _UniformRandomNumberGenerator& __urng,
04805                    const param_type& __p)
04806         { this->__generate_impl(__f, __t, __urng, __p); }
04807 
04808       template<typename _UniformRandomNumberGenerator>
04809         void
04810         __generate(result_type* __f, result_type* __t,
04811                    _UniformRandomNumberGenerator& __urng,
04812                    const param_type& __p)
04813         { this->__generate_impl(__f, __t, __urng, __p); }
04814 
04815       /**
04816        * @brief Return true if two Weibull distributions have the same
04817        *        parameters.
04818        */
04819       friend bool
04820       operator==(const weibull_distribution& __d1,
04821                  const weibull_distribution& __d2)
04822       { return __d1._M_param == __d2._M_param; }
04823 
04824     private:
04825       template<typename _ForwardIterator,
04826                typename _UniformRandomNumberGenerator>
04827         void
04828         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
04829                         _UniformRandomNumberGenerator& __urng,
04830                         const param_type& __p);
04831 
04832       param_type _M_param;
04833     };
04834 
04835    /**
04836     * @brief Return true if two Weibull distributions have different
04837     *        parameters.
04838     */
04839   template<typename _RealType>
04840     inline bool
04841     operator!=(const std::weibull_distribution<_RealType>& __d1,
04842                const std::weibull_distribution<_RealType>& __d2)
04843     { return !(__d1 == __d2); }
04844 
04845   /**
04846    * @brief Inserts a %weibull_distribution random number distribution
04847    * @p __x into the output stream @p __os.
04848    *
04849    * @param __os An output stream.
04850    * @param __x  A %weibull_distribution random number distribution.
04851    *
04852    * @returns The output stream with the state of @p __x inserted or in
04853    * an error state.
04854    */
04855   template<typename _RealType, typename _CharT, typename _Traits>
04856     std::basic_ostream<_CharT, _Traits>&
04857     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
04858                const std::weibull_distribution<_RealType>& __x);
04859 
04860   /**
04861    * @brief Extracts a %weibull_distribution random number distribution
04862    * @p __x from the input stream @p __is.
04863    *
04864    * @param __is An input stream.
04865    * @param __x A %weibull_distribution random number
04866    *            generator engine.
04867    *
04868    * @returns The input stream with @p __x extracted or in an error state.
04869    */
04870   template<typename _RealType, typename _CharT, typename _Traits>
04871     std::basic_istream<_CharT, _Traits>&
04872     operator>>(std::basic_istream<_CharT, _Traits>& __is,
04873                std::weibull_distribution<_RealType>& __x);
04874 
04875 
04876   /**
04877    * @brief A extreme_value_distribution random number distribution.
04878    *
04879    * The formula for the normal probability mass function is
04880    * @f[
04881    *     p(x|a,b) = \frac{1}{b}
04882    *                \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) 
04883    * @f]
04884    */
04885   template<typename _RealType = double>
04886     class extreme_value_distribution
04887     {
04888       static_assert(std::is_floating_point<_RealType>::value,
04889                     "template argument not a floating point type");
04890 
04891     public:
04892       /** The type of the range of the distribution. */
04893       typedef _RealType result_type;
04894       /** Parameter type. */
04895       struct param_type
04896       {
04897         typedef extreme_value_distribution<_RealType> distribution_type;
04898 
04899         explicit
04900         param_type(_RealType __a = _RealType(0),
04901                    _RealType __b = _RealType(1))
04902         : _M_a(__a), _M_b(__b)
04903         { }
04904 
04905         _RealType
04906         a() const
04907         { return _M_a; }
04908 
04909         _RealType
04910         b() const
04911         { return _M_b; }
04912 
04913         friend bool
04914         operator==(const param_type& __p1, const param_type& __p2)
04915         { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
04916 
04917       private:
04918         _RealType _M_a;
04919         _RealType _M_b;
04920       };
04921 
04922       explicit
04923       extreme_value_distribution(_RealType __a = _RealType(0),
04924                                  _RealType __b = _RealType(1))
04925       : _M_param(__a, __b)
04926       { }
04927 
04928       explicit
04929       extreme_value_distribution(const param_type& __p)
04930       : _M_param(__p)
04931       { }
04932 
04933       /**
04934        * @brief Resets the distribution state.
04935        */
04936       void
04937       reset()
04938       { }
04939 
04940       /**
04941        * @brief Return the @f$a@f$ parameter of the distribution.
04942        */
04943       _RealType
04944       a() const
04945       { return _M_param.a(); }
04946 
04947       /**
04948        * @brief Return the @f$b@f$ parameter of the distribution.
04949        */
04950       _RealType
04951       b() const
04952       { return _M_param.b(); }
04953 
04954       /**
04955        * @brief Returns the parameter set of the distribution.
04956        */
04957       param_type
04958       param() const
04959       { return _M_param; }
04960 
04961       /**
04962        * @brief Sets the parameter set of the distribution.
04963        * @param __param The new parameter set of the distribution.
04964        */
04965       void
04966       param(const param_type& __param)
04967       { _M_param = __param; }
04968 
04969       /**
04970        * @brief Returns the greatest lower bound value of the distribution.
04971        */
04972       result_type
04973       min() const
04974       { return std::numeric_limits<result_type>::lowest(); }
04975 
04976       /**
04977        * @brief Returns the least upper bound value of the distribution.
04978        */
04979       result_type
04980       max() const
04981       { return std::numeric_limits<result_type>::max(); }
04982 
04983       /**
04984        * @brief Generating functions.
04985        */
04986       template<typename _UniformRandomNumberGenerator>
04987         result_type
04988         operator()(_UniformRandomNumberGenerator& __urng)
04989         { return this->operator()(__urng, _M_param); }
04990 
04991       template<typename _UniformRandomNumberGenerator>
04992         result_type
04993         operator()(_UniformRandomNumberGenerator& __urng,
04994                    const param_type& __p);
04995 
04996       template<typename _ForwardIterator,
04997                typename _UniformRandomNumberGenerator>
04998         void
04999         __generate(_ForwardIterator __f, _ForwardIterator __t,
05000                    _UniformRandomNumberGenerator& __urng)
05001         { this->__generate(__f, __t, __urng, _M_param); }
05002 
05003       template<typename _ForwardIterator,
05004                typename _UniformRandomNumberGenerator>
05005         void
05006         __generate(_ForwardIterator __f, _ForwardIterator __t,
05007                    _UniformRandomNumberGenerator& __urng,
05008                    const param_type& __p)
05009         { this->__generate_impl(__f, __t, __urng, __p); }
05010 
05011       template<typename _UniformRandomNumberGenerator>
05012         void
05013         __generate(result_type* __f, result_type* __t,
05014                    _UniformRandomNumberGenerator& __urng,
05015                    const param_type& __p)
05016         { this->__generate_impl(__f, __t, __urng, __p); }
05017 
05018       /**
05019        * @brief Return true if two extreme value distributions have the same
05020        *        parameters.
05021        */
05022       friend bool
05023       operator==(const extreme_value_distribution& __d1,
05024                  const extreme_value_distribution& __d2)
05025       { return __d1._M_param == __d2._M_param; }
05026 
05027     private:
05028       template<typename _ForwardIterator,
05029                typename _UniformRandomNumberGenerator>
05030         void
05031         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05032                         _UniformRandomNumberGenerator& __urng,
05033                         const param_type& __p);
05034 
05035       param_type _M_param;
05036     };
05037 
05038   /**
05039     * @brief Return true if two extreme value distributions have different
05040     *        parameters.
05041    */
05042   template<typename _RealType>
05043     inline bool
05044     operator!=(const std::extreme_value_distribution<_RealType>& __d1,
05045                const std::extreme_value_distribution<_RealType>& __d2)
05046     { return !(__d1 == __d2); }
05047 
05048   /**
05049    * @brief Inserts a %extreme_value_distribution random number distribution
05050    * @p __x into the output stream @p __os.
05051    *
05052    * @param __os An output stream.
05053    * @param __x  A %extreme_value_distribution random number distribution.
05054    *
05055    * @returns The output stream with the state of @p __x inserted or in
05056    * an error state.
05057    */
05058   template<typename _RealType, typename _CharT, typename _Traits>
05059     std::basic_ostream<_CharT, _Traits>&
05060     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05061                const std::extreme_value_distribution<_RealType>& __x);
05062 
05063   /**
05064    * @brief Extracts a %extreme_value_distribution random number
05065    *        distribution @p __x from the input stream @p __is.
05066    *
05067    * @param __is An input stream.
05068    * @param __x A %extreme_value_distribution random number
05069    *            generator engine.
05070    *
05071    * @returns The input stream with @p __x extracted or in an error state.
05072    */
05073   template<typename _RealType, typename _CharT, typename _Traits>
05074     std::basic_istream<_CharT, _Traits>&
05075     operator>>(std::basic_istream<_CharT, _Traits>& __is,
05076                std::extreme_value_distribution<_RealType>& __x);
05077 
05078 
05079   /**
05080    * @brief A discrete_distribution random number distribution.
05081    *
05082    * The formula for the discrete probability mass function is
05083    *
05084    */
05085   template<typename _IntType = int>
05086     class discrete_distribution
05087     {
05088       static_assert(std::is_integral<_IntType>::value,
05089                     "template argument not an integral type");
05090 
05091     public:
05092       /** The type of the range of the distribution. */
05093       typedef _IntType result_type;
05094       /** Parameter type. */
05095       struct param_type
05096       {
05097         typedef discrete_distribution<_IntType> distribution_type;
05098         friend class discrete_distribution<_IntType>;
05099 
05100         param_type()
05101         : _M_prob(), _M_cp()
05102         { }
05103 
05104         template<typename _InputIterator>
05105           param_type(_InputIterator __wbegin,
05106                      _InputIterator __wend)
05107           : _M_prob(__wbegin, __wend), _M_cp()
05108           { _M_initialize(); }
05109 
05110         param_type(initializer_list<double> __wil)
05111         : _M_prob(__wil.begin(), __wil.end()), _M_cp()
05112         { _M_initialize(); }
05113 
05114         template<typename _Func>
05115           param_type(size_t __nw, double __xmin, double __xmax,
05116                      _Func __fw);
05117 
05118         // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05119         param_type(const param_type&) = default;
05120         param_type& operator=(const param_type&) = default;
05121 
05122         std::vector<double>
05123         probabilities() const
05124         { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
05125 
05126         friend bool
05127         operator==(const param_type& __p1, const param_type& __p2)
05128         { return __p1._M_prob == __p2._M_prob; }
05129 
05130       private:
05131         void
05132         _M_initialize();
05133 
05134         std::vector<double> _M_prob;
05135         std::vector<double> _M_cp;
05136       };
05137 
05138       discrete_distribution()
05139       : _M_param()
05140       { }
05141 
05142       template<typename _InputIterator>
05143         discrete_distribution(_InputIterator __wbegin,
05144                               _InputIterator __wend)
05145         : _M_param(__wbegin, __wend)
05146         { }
05147 
05148       discrete_distribution(initializer_list<double> __wl)
05149       : _M_param(__wl)
05150       { }
05151 
05152       template<typename _Func>
05153         discrete_distribution(size_t __nw, double __xmin, double __xmax,
05154                               _Func __fw)
05155         : _M_param(__nw, __xmin, __xmax, __fw)
05156         { }
05157 
05158       explicit
05159       discrete_distribution(const param_type& __p)
05160       : _M_param(__p)
05161       { }
05162 
05163       /**
05164        * @brief Resets the distribution state.
05165        */
05166       void
05167       reset()
05168       { }
05169 
05170       /**
05171        * @brief Returns the probabilities of the distribution.
05172        */
05173       std::vector<double>
05174       probabilities() const
05175       {
05176         return _M_param._M_prob.empty()
05177           ? std::vector<double>(1, 1.0) : _M_param._M_prob;
05178       }
05179 
05180       /**
05181        * @brief Returns the parameter set of the distribution.
05182        */
05183       param_type
05184       param() const
05185       { return _M_param; }
05186 
05187       /**
05188        * @brief Sets the parameter set of the distribution.
05189        * @param __param The new parameter set of the distribution.
05190        */
05191       void
05192       param(const param_type& __param)
05193       { _M_param = __param; }
05194 
05195       /**
05196        * @brief Returns the greatest lower bound value of the distribution.
05197        */
05198       result_type
05199       min() const
05200       { return result_type(0); }
05201 
05202       /**
05203        * @brief Returns the least upper bound value of the distribution.
05204        */
05205       result_type
05206       max() const
05207       {
05208         return _M_param._M_prob.empty()
05209           ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
05210       }
05211 
05212       /**
05213        * @brief Generating functions.
05214        */
05215       template<typename _UniformRandomNumberGenerator>
05216         result_type
05217         operator()(_UniformRandomNumberGenerator& __urng)
05218         { return this->operator()(__urng, _M_param); }
05219 
05220       template<typename _UniformRandomNumberGenerator>
05221         result_type
05222         operator()(_UniformRandomNumberGenerator& __urng,
05223                    const param_type& __p);
05224 
05225       template<typename _ForwardIterator,
05226                typename _UniformRandomNumberGenerator>
05227         void
05228         __generate(_ForwardIterator __f, _ForwardIterator __t,
05229                    _UniformRandomNumberGenerator& __urng)
05230         { this->__generate(__f, __t, __urng, _M_param); }
05231 
05232       template<typename _ForwardIterator,
05233                typename _UniformRandomNumberGenerator>
05234         void
05235         __generate(_ForwardIterator __f, _ForwardIterator __t,
05236                    _UniformRandomNumberGenerator& __urng,
05237                    const param_type& __p)
05238         { this->__generate_impl(__f, __t, __urng, __p); }
05239 
05240       template<typename _UniformRandomNumberGenerator>
05241         void
05242         __generate(result_type* __f, result_type* __t,
05243                    _UniformRandomNumberGenerator& __urng,
05244                    const param_type& __p)
05245         { this->__generate_impl(__f, __t, __urng, __p); }
05246 
05247       /**
05248        * @brief Return true if two discrete distributions have the same
05249        *        parameters.
05250        */
05251       friend bool
05252       operator==(const discrete_distribution& __d1,
05253                  const discrete_distribution& __d2)
05254       { return __d1._M_param == __d2._M_param; }
05255 
05256       /**
05257        * @brief Inserts a %discrete_distribution random number distribution
05258        * @p __x into the output stream @p __os.
05259        *
05260        * @param __os An output stream.
05261        * @param __x  A %discrete_distribution random number distribution.
05262        *
05263        * @returns The output stream with the state of @p __x inserted or in
05264        * an error state.
05265        */
05266       template<typename _IntType1, typename _CharT, typename _Traits>
05267         friend std::basic_ostream<_CharT, _Traits>&
05268         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05269                    const std::discrete_distribution<_IntType1>& __x);
05270 
05271       /**
05272        * @brief Extracts a %discrete_distribution random number distribution
05273        * @p __x from the input stream @p __is.
05274        *
05275        * @param __is An input stream.
05276        * @param __x A %discrete_distribution random number
05277        *            generator engine.
05278        *
05279        * @returns The input stream with @p __x extracted or in an error
05280        *          state.
05281        */
05282       template<typename _IntType1, typename _CharT, typename _Traits>
05283         friend std::basic_istream<_CharT, _Traits>&
05284         operator>>(std::basic_istream<_CharT, _Traits>& __is,
05285                    std::discrete_distribution<_IntType1>& __x);
05286 
05287     private:
05288       template<typename _ForwardIterator,
05289                typename _UniformRandomNumberGenerator>
05290         void
05291         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05292                         _UniformRandomNumberGenerator& __urng,
05293                         const param_type& __p);
05294 
05295       param_type _M_param;
05296     };
05297 
05298   /**
05299     * @brief Return true if two discrete distributions have different
05300     *        parameters.
05301     */
05302   template<typename _IntType>
05303     inline bool
05304     operator!=(const std::discrete_distribution<_IntType>& __d1,
05305                const std::discrete_distribution<_IntType>& __d2)
05306     { return !(__d1 == __d2); }
05307 
05308 
05309   /**
05310    * @brief A piecewise_constant_distribution random number distribution.
05311    *
05312    * The formula for the piecewise constant probability mass function is
05313    *
05314    */
05315   template<typename _RealType = double>
05316     class piecewise_constant_distribution
05317     {
05318       static_assert(std::is_floating_point<_RealType>::value,
05319                     "template argument not a floating point type");
05320 
05321     public:
05322       /** The type of the range of the distribution. */
05323       typedef _RealType result_type;
05324       /** Parameter type. */
05325       struct param_type
05326       {
05327         typedef piecewise_constant_distribution<_RealType> distribution_type;
05328         friend class piecewise_constant_distribution<_RealType>;
05329 
05330         param_type()
05331         : _M_int(), _M_den(), _M_cp()
05332         { }
05333 
05334         template<typename _InputIteratorB, typename _InputIteratorW>
05335           param_type(_InputIteratorB __bfirst,
05336                      _InputIteratorB __bend,
05337                      _InputIteratorW __wbegin);
05338 
05339         template<typename _Func>
05340           param_type(initializer_list<_RealType> __bi, _Func __fw);
05341 
05342         template<typename _Func>
05343           param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
05344                      _Func __fw);
05345 
05346         // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05347         param_type(const param_type&) = default;
05348         param_type& operator=(const param_type&) = default;
05349 
05350         std::vector<_RealType>
05351         intervals() const
05352         {
05353           if (_M_int.empty())
05354             {
05355               std::vector<_RealType> __tmp(2);
05356               __tmp[1] = _RealType(1);
05357               return __tmp;
05358             }
05359           else
05360             return _M_int;
05361         }
05362 
05363         std::vector<double>
05364         densities() const
05365         { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
05366 
05367         friend bool
05368         operator==(const param_type& __p1, const param_type& __p2)
05369         { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
05370 
05371       private:
05372         void
05373         _M_initialize();
05374 
05375         std::vector<_RealType> _M_int;
05376         std::vector<double> _M_den;
05377         std::vector<double> _M_cp;
05378       };
05379 
05380       explicit
05381       piecewise_constant_distribution()
05382       : _M_param()
05383       { }
05384 
05385       template<typename _InputIteratorB, typename _InputIteratorW>
05386         piecewise_constant_distribution(_InputIteratorB __bfirst,
05387                                         _InputIteratorB __bend,
05388                                         _InputIteratorW __wbegin)
05389         : _M_param(__bfirst, __bend, __wbegin)
05390         { }
05391 
05392       template<typename _Func>
05393         piecewise_constant_distribution(initializer_list<_RealType> __bl,
05394                                         _Func __fw)
05395         : _M_param(__bl, __fw)
05396         { }
05397 
05398       template<typename _Func>
05399         piecewise_constant_distribution(size_t __nw,
05400                                         _RealType __xmin, _RealType __xmax,
05401                                         _Func __fw)
05402         : _M_param(__nw, __xmin, __xmax, __fw)
05403         { }
05404 
05405       explicit
05406       piecewise_constant_distribution(const param_type& __p)
05407       : _M_param(__p)
05408       { }
05409 
05410       /**
05411        * @brief Resets the distribution state.
05412        */
05413       void
05414       reset()
05415       { }
05416 
05417       /**
05418        * @brief Returns a vector of the intervals.
05419        */
05420       std::vector<_RealType>
05421       intervals() const
05422       {
05423         if (_M_param._M_int.empty())
05424           {
05425             std::vector<_RealType> __tmp(2);
05426             __tmp[1] = _RealType(1);
05427             return __tmp;
05428           }
05429         else
05430           return _M_param._M_int;
05431       }
05432 
05433       /**
05434        * @brief Returns a vector of the probability densities.
05435        */
05436       std::vector<double>
05437       densities() const
05438       {
05439         return _M_param._M_den.empty()
05440           ? std::vector<double>(1, 1.0) : _M_param._M_den;
05441       }
05442 
05443       /**
05444        * @brief Returns the parameter set of the distribution.
05445        */
05446       param_type
05447       param() const
05448       { return _M_param; }
05449 
05450       /**
05451        * @brief Sets the parameter set of the distribution.
05452        * @param __param The new parameter set of the distribution.
05453        */
05454       void
05455       param(const param_type& __param)
05456       { _M_param = __param; }
05457 
05458       /**
05459        * @brief Returns the greatest lower bound value of the distribution.
05460        */
05461       result_type
05462       min() const
05463       {
05464         return _M_param._M_int.empty()
05465           ? result_type(0) : _M_param._M_int.front();
05466       }
05467 
05468       /**
05469        * @brief Returns the least upper bound value of the distribution.
05470        */
05471       result_type
05472       max() const
05473       {
05474         return _M_param._M_int.empty()
05475           ? result_type(1) : _M_param._M_int.back();
05476       }
05477 
05478       /**
05479        * @brief Generating functions.
05480        */
05481       template<typename _UniformRandomNumberGenerator>
05482         result_type
05483         operator()(_UniformRandomNumberGenerator& __urng)
05484         { return this->operator()(__urng, _M_param); }
05485 
05486       template<typename _UniformRandomNumberGenerator>
05487         result_type
05488         operator()(_UniformRandomNumberGenerator& __urng,
05489                    const param_type& __p);
05490 
05491       template<typename _ForwardIterator,
05492                typename _UniformRandomNumberGenerator>
05493         void
05494         __generate(_ForwardIterator __f, _ForwardIterator __t,
05495                    _UniformRandomNumberGenerator& __urng)
05496         { this->__generate(__f, __t, __urng, _M_param); }
05497 
05498       template<typename _ForwardIterator,
05499                typename _UniformRandomNumberGenerator>
05500         void
05501         __generate(_ForwardIterator __f, _ForwardIterator __t,
05502                    _UniformRandomNumberGenerator& __urng,
05503                    const param_type& __p)
05504         { this->__generate_impl(__f, __t, __urng, __p); }
05505 
05506       template<typename _UniformRandomNumberGenerator>
05507         void
05508         __generate(result_type* __f, result_type* __t,
05509                    _UniformRandomNumberGenerator& __urng,
05510                    const param_type& __p)
05511         { this->__generate_impl(__f, __t, __urng, __p); }
05512 
05513       /**
05514        * @brief Return true if two piecewise constant distributions have the
05515        *        same parameters.
05516        */
05517       friend bool
05518       operator==(const piecewise_constant_distribution& __d1,
05519                  const piecewise_constant_distribution& __d2)
05520       { return __d1._M_param == __d2._M_param; }
05521 
05522       /**
05523        * @brief Inserts a %piecewise_constant_distribution random
05524        *        number distribution @p __x into the output stream @p __os.
05525        *
05526        * @param __os An output stream.
05527        * @param __x  A %piecewise_constant_distribution random number
05528        *             distribution.
05529        *
05530        * @returns The output stream with the state of @p __x inserted or in
05531        * an error state.
05532        */
05533       template<typename _RealType1, typename _CharT, typename _Traits>
05534         friend std::basic_ostream<_CharT, _Traits>&
05535         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05536                    const std::piecewise_constant_distribution<_RealType1>& __x);
05537 
05538       /**
05539        * @brief Extracts a %piecewise_constant_distribution random
05540        *        number distribution @p __x from the input stream @p __is.
05541        *
05542        * @param __is An input stream.
05543        * @param __x A %piecewise_constant_distribution random number
05544        *            generator engine.
05545        *
05546        * @returns The input stream with @p __x extracted or in an error
05547        *          state.
05548        */
05549       template<typename _RealType1, typename _CharT, typename _Traits>
05550         friend std::basic_istream<_CharT, _Traits>&
05551         operator>>(std::basic_istream<_CharT, _Traits>& __is,
05552                    std::piecewise_constant_distribution<_RealType1>& __x);
05553 
05554     private:
05555       template<typename _ForwardIterator,
05556                typename _UniformRandomNumberGenerator>
05557         void
05558         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05559                         _UniformRandomNumberGenerator& __urng,
05560                         const param_type& __p);
05561 
05562       param_type _M_param;
05563     };
05564 
05565   /**
05566     * @brief Return true if two piecewise constant distributions have 
05567     *        different parameters.
05568    */
05569   template<typename _RealType>
05570     inline bool
05571     operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
05572                const std::piecewise_constant_distribution<_RealType>& __d2)
05573     { return !(__d1 == __d2); }
05574 
05575 
05576   /**
05577    * @brief A piecewise_linear_distribution random number distribution.
05578    *
05579    * The formula for the piecewise linear probability mass function is
05580    *
05581    */
05582   template<typename _RealType = double>
05583     class piecewise_linear_distribution
05584     {
05585       static_assert(std::is_floating_point<_RealType>::value,
05586                     "template argument not a floating point type");
05587 
05588     public:
05589       /** The type of the range of the distribution. */
05590       typedef _RealType result_type;
05591       /** Parameter type. */
05592       struct param_type
05593       {
05594         typedef piecewise_linear_distribution<_RealType> distribution_type;
05595         friend class piecewise_linear_distribution<_RealType>;
05596 
05597         param_type()
05598         : _M_int(), _M_den(), _M_cp(), _M_m()
05599         { }
05600 
05601         template<typename _InputIteratorB, typename _InputIteratorW>
05602           param_type(_InputIteratorB __bfirst,
05603                      _InputIteratorB __bend,
05604                      _InputIteratorW __wbegin);
05605 
05606         template<typename _Func>
05607           param_type(initializer_list<_RealType> __bl, _Func __fw);
05608 
05609         template<typename _Func>
05610           param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
05611                      _Func __fw);
05612 
05613         // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
05614         param_type(const param_type&) = default;
05615         param_type& operator=(const param_type&) = default;
05616 
05617         std::vector<_RealType>
05618         intervals() const
05619         {
05620           if (_M_int.empty())
05621             {
05622               std::vector<_RealType> __tmp(2);
05623               __tmp[1] = _RealType(1);
05624               return __tmp;
05625             }
05626           else
05627             return _M_int;
05628         }
05629 
05630         std::vector<double>
05631         densities() const
05632         { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
05633 
05634         friend bool
05635         operator==(const param_type& __p1, const param_type& __p2)
05636         { return (__p1._M_int == __p2._M_int
05637                   && __p1._M_den == __p2._M_den); }
05638 
05639       private:
05640         void
05641         _M_initialize();
05642 
05643         std::vector<_RealType> _M_int;
05644         std::vector<double> _M_den;
05645         std::vector<double> _M_cp;
05646         std::vector<double> _M_m;
05647       };
05648 
05649       explicit
05650       piecewise_linear_distribution()
05651       : _M_param()
05652       { }
05653 
05654       template<typename _InputIteratorB, typename _InputIteratorW>
05655         piecewise_linear_distribution(_InputIteratorB __bfirst,
05656                                       _InputIteratorB __bend,
05657                                       _InputIteratorW __wbegin)
05658         : _M_param(__bfirst, __bend, __wbegin)
05659         { }
05660 
05661       template<typename _Func>
05662         piecewise_linear_distribution(initializer_list<_RealType> __bl,
05663                                       _Func __fw)
05664         : _M_param(__bl, __fw)
05665         { }
05666 
05667       template<typename _Func>
05668         piecewise_linear_distribution(size_t __nw,
05669                                       _RealType __xmin, _RealType __xmax,
05670                                       _Func __fw)
05671         : _M_param(__nw, __xmin, __xmax, __fw)
05672         { }
05673 
05674       explicit
05675       piecewise_linear_distribution(const param_type& __p)
05676       : _M_param(__p)
05677       { }
05678 
05679       /**
05680        * Resets the distribution state.
05681        */
05682       void
05683       reset()
05684       { }
05685 
05686       /**
05687        * @brief Return the intervals of the distribution.
05688        */
05689       std::vector<_RealType>
05690       intervals() const
05691       {
05692         if (_M_param._M_int.empty())
05693           {
05694             std::vector<_RealType> __tmp(2);
05695             __tmp[1] = _RealType(1);
05696             return __tmp;
05697           }
05698         else
05699           return _M_param._M_int;
05700       }
05701 
05702       /**
05703        * @brief Return a vector of the probability densities of the
05704        *        distribution.
05705        */
05706       std::vector<double>
05707       densities() const
05708       {
05709         return _M_param._M_den.empty()
05710           ? std::vector<double>(2, 1.0) : _M_param._M_den;
05711       }
05712 
05713       /**
05714        * @brief Returns the parameter set of the distribution.
05715        */
05716       param_type
05717       param() const
05718       { return _M_param; }
05719 
05720       /**
05721        * @brief Sets the parameter set of the distribution.
05722        * @param __param The new parameter set of the distribution.
05723        */
05724       void
05725       param(const param_type& __param)
05726       { _M_param = __param; }
05727 
05728       /**
05729        * @brief Returns the greatest lower bound value of the distribution.
05730        */
05731       result_type
05732       min() const
05733       {
05734         return _M_param._M_int.empty()
05735           ? result_type(0) : _M_param._M_int.front();
05736       }
05737 
05738       /**
05739        * @brief Returns the least upper bound value of the distribution.
05740        */
05741       result_type
05742       max() const
05743       {
05744         return _M_param._M_int.empty()
05745           ? result_type(1) : _M_param._M_int.back();
05746       }
05747 
05748       /**
05749        * @brief Generating functions.
05750        */
05751       template<typename _UniformRandomNumberGenerator>
05752         result_type
05753         operator()(_UniformRandomNumberGenerator& __urng)
05754         { return this->operator()(__urng, _M_param); }
05755 
05756       template<typename _UniformRandomNumberGenerator>
05757         result_type
05758         operator()(_UniformRandomNumberGenerator& __urng,
05759                    const param_type& __p);
05760 
05761       template<typename _ForwardIterator,
05762                typename _UniformRandomNumberGenerator>
05763         void
05764         __generate(_ForwardIterator __f, _ForwardIterator __t,
05765                    _UniformRandomNumberGenerator& __urng)
05766         { this->__generate(__f, __t, __urng, _M_param); }
05767 
05768       template<typename _ForwardIterator,
05769                typename _UniformRandomNumberGenerator>
05770         void
05771         __generate(_ForwardIterator __f, _ForwardIterator __t,
05772                    _UniformRandomNumberGenerator& __urng,
05773                    const param_type& __p)
05774         { this->__generate_impl(__f, __t, __urng, __p); }
05775 
05776       template<typename _UniformRandomNumberGenerator>
05777         void
05778         __generate(result_type* __f, result_type* __t,
05779                    _UniformRandomNumberGenerator& __urng,
05780                    const param_type& __p)
05781         { this->__generate_impl(__f, __t, __urng, __p); }
05782 
05783       /**
05784        * @brief Return true if two piecewise linear distributions have the
05785        *        same parameters.
05786        */
05787       friend bool
05788       operator==(const piecewise_linear_distribution& __d1,
05789                  const piecewise_linear_distribution& __d2)
05790       { return __d1._M_param == __d2._M_param; }
05791 
05792       /**
05793        * @brief Inserts a %piecewise_linear_distribution random number
05794        *        distribution @p __x into the output stream @p __os.
05795        *
05796        * @param __os An output stream.
05797        * @param __x  A %piecewise_linear_distribution random number
05798        *             distribution.
05799        *
05800        * @returns The output stream with the state of @p __x inserted or in
05801        *          an error state.
05802        */
05803       template<typename _RealType1, typename _CharT, typename _Traits>
05804         friend std::basic_ostream<_CharT, _Traits>&
05805         operator<<(std::basic_ostream<_CharT, _Traits>& __os,
05806                    const std::piecewise_linear_distribution<_RealType1>& __x);
05807 
05808       /**
05809        * @brief Extracts a %piecewise_linear_distribution random number
05810        *        distribution @p __x from the input stream @p __is.
05811        *
05812        * @param __is An input stream.
05813        * @param __x  A %piecewise_linear_distribution random number
05814        *             generator engine.
05815        *
05816        * @returns The input stream with @p __x extracted or in an error
05817        *          state.
05818        */
05819       template<typename _RealType1, typename _CharT, typename _Traits>
05820         friend std::basic_istream<_CharT, _Traits>&
05821         operator>>(std::basic_istream<_CharT, _Traits>& __is,
05822                    std::piecewise_linear_distribution<_RealType1>& __x);
05823 
05824     private:
05825       template<typename _ForwardIterator,
05826                typename _UniformRandomNumberGenerator>
05827         void
05828         __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
05829                         _UniformRandomNumberGenerator& __urng,
05830                         const param_type& __p);
05831 
05832       param_type _M_param;
05833     };
05834 
05835   /**
05836     * @brief Return true if two piecewise linear distributions have
05837     *        different parameters.
05838    */
05839   template<typename _RealType>
05840     inline bool
05841     operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
05842                const std::piecewise_linear_distribution<_RealType>& __d2)
05843     { return !(__d1 == __d2); }
05844 
05845 
05846   /* @} */ // group random_distributions_poisson
05847 
05848   /* @} */ // group random_distributions
05849 
05850   /**
05851    * @addtogroup random_utilities Random Number Utilities
05852    * @ingroup random
05853    * @{
05854    */
05855 
05856   /**
05857    * @brief The seed_seq class generates sequences of seeds for random
05858    *        number generators.
05859    */
05860   class seed_seq
05861   {
05862 
05863   public:
05864     /** The type of the seed vales. */
05865     typedef uint_least32_t result_type;
05866 
05867     /** Default constructor. */
05868     seed_seq()
05869     : _M_v()
05870     { }
05871 
05872     template<typename _IntType>
05873       seed_seq(std::initializer_list<_IntType> il);
05874 
05875     template<typename _InputIterator>
05876       seed_seq(_InputIterator __begin, _InputIterator __end);
05877 
05878     // generating functions
05879     template<typename _RandomAccessIterator>
05880       void
05881       generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
05882 
05883     // property functions
05884     size_t size() const
05885     { return _M_v.size(); }
05886 
05887     template<typename OutputIterator>
05888       void
05889       param(OutputIterator __dest) const
05890       { std::copy(_M_v.begin(), _M_v.end(), __dest); }
05891 
05892   private:
05893     ///
05894     std::vector<result_type> _M_v;
05895   };
05896 
05897   /* @} */ // group random_utilities
05898 
05899   /* @} */ // group random
05900 
05901 _GLIBCXX_END_NAMESPACE_VERSION
05902 } // namespace std
05903 
05904 #endif