Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:39

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H
0010 #define _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H
0011 
0012 #include <__cxx03/__algorithm/equal.h>
0013 #include <__cxx03/__algorithm/min.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__random/is_seed_sequence.h>
0016 #include <__cxx03/cstddef>
0017 #include <__cxx03/cstdint>
0018 #include <__cxx03/iosfwd>
0019 #include <__cxx03/limits>
0020 
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 #  pragma GCC system_header
0023 #endif
0024 
0025 _LIBCPP_PUSH_MACROS
0026 #include <__cxx03/__undef_macros>
0027 
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029 
0030 template <class _UIntType,
0031           size_t __w,
0032           size_t __n,
0033           size_t __m,
0034           size_t __r,
0035           _UIntType __a,
0036           size_t __u,
0037           _UIntType __d,
0038           size_t __s,
0039           _UIntType __b,
0040           size_t __t,
0041           _UIntType __c,
0042           size_t __l,
0043           _UIntType __f>
0044 class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
0045 
0046 template <class _UInt,
0047           size_t _Wp,
0048           size_t _Np,
0049           size_t _Mp,
0050           size_t _Rp,
0051           _UInt _Ap,
0052           size_t _Up,
0053           _UInt _Dp,
0054           size_t _Sp,
0055           _UInt _Bp,
0056           size_t _Tp,
0057           _UInt _Cp,
0058           size_t _Lp,
0059           _UInt _Fp>
0060 _LIBCPP_HIDE_FROM_ABI bool
0061 operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0062            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
0063 
0064 template <class _UInt,
0065           size_t _Wp,
0066           size_t _Np,
0067           size_t _Mp,
0068           size_t _Rp,
0069           _UInt _Ap,
0070           size_t _Up,
0071           _UInt _Dp,
0072           size_t _Sp,
0073           _UInt _Bp,
0074           size_t _Tp,
0075           _UInt _Cp,
0076           size_t _Lp,
0077           _UInt _Fp>
0078 _LIBCPP_HIDE_FROM_ABI bool
0079 operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0080            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
0081 
0082 template <class _CharT,
0083           class _Traits,
0084           class _UInt,
0085           size_t _Wp,
0086           size_t _Np,
0087           size_t _Mp,
0088           size_t _Rp,
0089           _UInt _Ap,
0090           size_t _Up,
0091           _UInt _Dp,
0092           size_t _Sp,
0093           _UInt _Bp,
0094           size_t _Tp,
0095           _UInt _Cp,
0096           size_t _Lp,
0097           _UInt _Fp>
0098 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0099 operator<<(basic_ostream<_CharT, _Traits>& __os,
0100            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
0101 
0102 template <class _CharT,
0103           class _Traits,
0104           class _UInt,
0105           size_t _Wp,
0106           size_t _Np,
0107           size_t _Mp,
0108           size_t _Rp,
0109           _UInt _Ap,
0110           size_t _Up,
0111           _UInt _Dp,
0112           size_t _Sp,
0113           _UInt _Bp,
0114           size_t _Tp,
0115           _UInt _Cp,
0116           size_t _Lp,
0117           _UInt _Fp>
0118 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0119 operator>>(basic_istream<_CharT, _Traits>& __is,
0120            mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
0121 
0122 template <class _UIntType,
0123           size_t __w,
0124           size_t __n,
0125           size_t __m,
0126           size_t __r,
0127           _UIntType __a,
0128           size_t __u,
0129           _UIntType __d,
0130           size_t __s,
0131           _UIntType __b,
0132           size_t __t,
0133           _UIntType __c,
0134           size_t __l,
0135           _UIntType __f>
0136 class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine {
0137 public:
0138   // types
0139   typedef _UIntType result_type;
0140 
0141 private:
0142   result_type __x_[__n];
0143   size_t __i_;
0144 
0145   static_assert(0 < __m, "mersenne_twister_engine invalid parameters");
0146   static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
0147   static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
0148   static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
0149   static_assert(2 <= __w, "mersenne_twister_engine invalid parameters");
0150   static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
0151   static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
0152   static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
0153   static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
0154   static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
0155 
0156 public:
0157   static _LIBCPP_CONSTEXPR const result_type _Min = 0;
0158   static _LIBCPP_CONSTEXPR const result_type _Max =
0159       __w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1);
0160   static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
0161   static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
0162   static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
0163   static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
0164   static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
0165   static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
0166 
0167   // engine characteristics
0168   static _LIBCPP_CONSTEXPR const size_t word_size                      = __w;
0169   static _LIBCPP_CONSTEXPR const size_t state_size                     = __n;
0170   static _LIBCPP_CONSTEXPR const size_t shift_size                     = __m;
0171   static _LIBCPP_CONSTEXPR const size_t mask_bits                      = __r;
0172   static _LIBCPP_CONSTEXPR const result_type xor_mask                  = __a;
0173   static _LIBCPP_CONSTEXPR const size_t tempering_u                    = __u;
0174   static _LIBCPP_CONSTEXPR const result_type tempering_d               = __d;
0175   static _LIBCPP_CONSTEXPR const size_t tempering_s                    = __s;
0176   static _LIBCPP_CONSTEXPR const result_type tempering_b               = __b;
0177   static _LIBCPP_CONSTEXPR const size_t tempering_t                    = __t;
0178   static _LIBCPP_CONSTEXPR const result_type tempering_c               = __c;
0179   static _LIBCPP_CONSTEXPR const size_t tempering_l                    = __l;
0180   static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
0181   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
0182   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
0183   static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
0184 
0185   // constructors and seeding functions
0186 #ifndef _LIBCPP_CXX03_LANG
0187   _LIBCPP_HIDE_FROM_ABI mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
0188   _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }
0189 #else
0190   _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd = default_seed) { seed(__sd); }
0191 #endif
0192   template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>
0193   _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(_Sseq& __q) {
0194     seed(__q);
0195   }
0196   _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd = default_seed);
0197   template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>
0198   _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) {
0199     __seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());
0200   }
0201 
0202   // generating functions
0203   _LIBCPP_HIDE_FROM_ABI result_type operator()();
0204   _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) {
0205     for (; __z; --__z)
0206       operator()();
0207   }
0208 
0209   template <class _UInt,
0210             size_t _Wp,
0211             size_t _Np,
0212             size_t _Mp,
0213             size_t _Rp,
0214             _UInt _Ap,
0215             size_t _Up,
0216             _UInt _Dp,
0217             size_t _Sp,
0218             _UInt _Bp,
0219             size_t _Tp,
0220             _UInt _Cp,
0221             size_t _Lp,
0222             _UInt _Fp>
0223   friend bool operator==(
0224       const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0225       const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
0226 
0227   template <class _UInt,
0228             size_t _Wp,
0229             size_t _Np,
0230             size_t _Mp,
0231             size_t _Rp,
0232             _UInt _Ap,
0233             size_t _Up,
0234             _UInt _Dp,
0235             size_t _Sp,
0236             _UInt _Bp,
0237             size_t _Tp,
0238             _UInt _Cp,
0239             size_t _Lp,
0240             _UInt _Fp>
0241   friend bool operator!=(
0242       const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0243       const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
0244 
0245   template <class _CharT,
0246             class _Traits,
0247             class _UInt,
0248             size_t _Wp,
0249             size_t _Np,
0250             size_t _Mp,
0251             size_t _Rp,
0252             _UInt _Ap,
0253             size_t _Up,
0254             _UInt _Dp,
0255             size_t _Sp,
0256             _UInt _Bp,
0257             size_t _Tp,
0258             _UInt _Cp,
0259             size_t _Lp,
0260             _UInt _Fp>
0261   friend basic_ostream<_CharT, _Traits>& operator<<(
0262       basic_ostream<_CharT, _Traits>& __os,
0263       const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
0264 
0265   template <class _CharT,
0266             class _Traits,
0267             class _UInt,
0268             size_t _Wp,
0269             size_t _Np,
0270             size_t _Mp,
0271             size_t _Rp,
0272             _UInt _Ap,
0273             size_t _Up,
0274             _UInt _Dp,
0275             size_t _Sp,
0276             _UInt _Bp,
0277             size_t _Tp,
0278             _UInt _Cp,
0279             size_t _Lp,
0280             _UInt _Fp>
0281   friend basic_istream<_CharT, _Traits>&
0282   operator>>(basic_istream<_CharT, _Traits>& __is,
0283              mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
0284 
0285 private:
0286   template <class _Sseq>
0287   _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
0288   template <class _Sseq>
0289   _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
0290 
0291   template <size_t __count,
0292             __enable_if_t<__count< __w, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) {
0293     return (__x << __count) & _Max;
0294   }
0295 
0296   template <size_t __count, __enable_if_t<(__count >= __w), int> = 0>
0297   _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type) {
0298     return result_type(0);
0299   }
0300 
0301   template <size_t __count,
0302             __enable_if_t<__count< _Dt, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type __x) {
0303     return __x >> __count;
0304   }
0305 
0306   template <size_t __count, __enable_if_t<(__count >= _Dt), int> = 0>
0307   _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type) {
0308     return result_type(0);
0309   }
0310 };
0311 
0312 template <class _UIntType,
0313           size_t __w,
0314           size_t __n,
0315           size_t __m,
0316           size_t __r,
0317           _UIntType __a,
0318           size_t __u,
0319           _UIntType __d,
0320           size_t __s,
0321           _UIntType __b,
0322           size_t __t,
0323           _UIntType __c,
0324           size_t __l,
0325           _UIntType __f>
0326 _LIBCPP_CONSTEXPR const size_t
0327     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
0328 
0329 template <class _UIntType,
0330           size_t __w,
0331           size_t __n,
0332           size_t __m,
0333           size_t __r,
0334           _UIntType __a,
0335           size_t __u,
0336           _UIntType __d,
0337           size_t __s,
0338           _UIntType __b,
0339           size_t __t,
0340           _UIntType __c,
0341           size_t __l,
0342           _UIntType __f>
0343 _LIBCPP_CONSTEXPR const size_t
0344     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
0345 
0346 template <class _UIntType,
0347           size_t __w,
0348           size_t __n,
0349           size_t __m,
0350           size_t __r,
0351           _UIntType __a,
0352           size_t __u,
0353           _UIntType __d,
0354           size_t __s,
0355           _UIntType __b,
0356           size_t __t,
0357           _UIntType __c,
0358           size_t __l,
0359           _UIntType __f>
0360 _LIBCPP_CONSTEXPR const size_t
0361     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
0362 
0363 template <class _UIntType,
0364           size_t __w,
0365           size_t __n,
0366           size_t __m,
0367           size_t __r,
0368           _UIntType __a,
0369           size_t __u,
0370           _UIntType __d,
0371           size_t __s,
0372           _UIntType __b,
0373           size_t __t,
0374           _UIntType __c,
0375           size_t __l,
0376           _UIntType __f>
0377 _LIBCPP_CONSTEXPR const size_t
0378     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
0379 
0380 template <class _UIntType,
0381           size_t __w,
0382           size_t __n,
0383           size_t __m,
0384           size_t __r,
0385           _UIntType __a,
0386           size_t __u,
0387           _UIntType __d,
0388           size_t __s,
0389           _UIntType __b,
0390           size_t __t,
0391           _UIntType __c,
0392           size_t __l,
0393           _UIntType __f>
0394 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0395     _UIntType,
0396     __w,
0397     __n,
0398     __m,
0399     __r,
0400     __a,
0401     __u,
0402     __d,
0403     __s,
0404     __b,
0405     __t,
0406     __c,
0407     __l,
0408     __f>::result_type
0409     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
0410 
0411 template <class _UIntType,
0412           size_t __w,
0413           size_t __n,
0414           size_t __m,
0415           size_t __r,
0416           _UIntType __a,
0417           size_t __u,
0418           _UIntType __d,
0419           size_t __s,
0420           _UIntType __b,
0421           size_t __t,
0422           _UIntType __c,
0423           size_t __l,
0424           _UIntType __f>
0425 _LIBCPP_CONSTEXPR const size_t
0426     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
0427 
0428 template <class _UIntType,
0429           size_t __w,
0430           size_t __n,
0431           size_t __m,
0432           size_t __r,
0433           _UIntType __a,
0434           size_t __u,
0435           _UIntType __d,
0436           size_t __s,
0437           _UIntType __b,
0438           size_t __t,
0439           _UIntType __c,
0440           size_t __l,
0441           _UIntType __f>
0442 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0443     _UIntType,
0444     __w,
0445     __n,
0446     __m,
0447     __r,
0448     __a,
0449     __u,
0450     __d,
0451     __s,
0452     __b,
0453     __t,
0454     __c,
0455     __l,
0456     __f>::result_type
0457     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
0458 
0459 template <class _UIntType,
0460           size_t __w,
0461           size_t __n,
0462           size_t __m,
0463           size_t __r,
0464           _UIntType __a,
0465           size_t __u,
0466           _UIntType __d,
0467           size_t __s,
0468           _UIntType __b,
0469           size_t __t,
0470           _UIntType __c,
0471           size_t __l,
0472           _UIntType __f>
0473 _LIBCPP_CONSTEXPR const size_t
0474     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
0475 
0476 template <class _UIntType,
0477           size_t __w,
0478           size_t __n,
0479           size_t __m,
0480           size_t __r,
0481           _UIntType __a,
0482           size_t __u,
0483           _UIntType __d,
0484           size_t __s,
0485           _UIntType __b,
0486           size_t __t,
0487           _UIntType __c,
0488           size_t __l,
0489           _UIntType __f>
0490 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0491     _UIntType,
0492     __w,
0493     __n,
0494     __m,
0495     __r,
0496     __a,
0497     __u,
0498     __d,
0499     __s,
0500     __b,
0501     __t,
0502     __c,
0503     __l,
0504     __f>::result_type
0505     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
0506 
0507 template <class _UIntType,
0508           size_t __w,
0509           size_t __n,
0510           size_t __m,
0511           size_t __r,
0512           _UIntType __a,
0513           size_t __u,
0514           _UIntType __d,
0515           size_t __s,
0516           _UIntType __b,
0517           size_t __t,
0518           _UIntType __c,
0519           size_t __l,
0520           _UIntType __f>
0521 _LIBCPP_CONSTEXPR const size_t
0522     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
0523 
0524 template <class _UIntType,
0525           size_t __w,
0526           size_t __n,
0527           size_t __m,
0528           size_t __r,
0529           _UIntType __a,
0530           size_t __u,
0531           _UIntType __d,
0532           size_t __s,
0533           _UIntType __b,
0534           size_t __t,
0535           _UIntType __c,
0536           size_t __l,
0537           _UIntType __f>
0538 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0539     _UIntType,
0540     __w,
0541     __n,
0542     __m,
0543     __r,
0544     __a,
0545     __u,
0546     __d,
0547     __s,
0548     __b,
0549     __t,
0550     __c,
0551     __l,
0552     __f>::result_type
0553     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
0554 
0555 template <class _UIntType,
0556           size_t __w,
0557           size_t __n,
0558           size_t __m,
0559           size_t __r,
0560           _UIntType __a,
0561           size_t __u,
0562           _UIntType __d,
0563           size_t __s,
0564           _UIntType __b,
0565           size_t __t,
0566           _UIntType __c,
0567           size_t __l,
0568           _UIntType __f>
0569 _LIBCPP_CONSTEXPR const size_t
0570     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
0571 
0572 template <class _UIntType,
0573           size_t __w,
0574           size_t __n,
0575           size_t __m,
0576           size_t __r,
0577           _UIntType __a,
0578           size_t __u,
0579           _UIntType __d,
0580           size_t __s,
0581           _UIntType __b,
0582           size_t __t,
0583           _UIntType __c,
0584           size_t __l,
0585           _UIntType __f>
0586 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0587     _UIntType,
0588     __w,
0589     __n,
0590     __m,
0591     __r,
0592     __a,
0593     __u,
0594     __d,
0595     __s,
0596     __b,
0597     __t,
0598     __c,
0599     __l,
0600     __f>::result_type
0601     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::
0602         initialization_multiplier;
0603 
0604 template <class _UIntType,
0605           size_t __w,
0606           size_t __n,
0607           size_t __m,
0608           size_t __r,
0609           _UIntType __a,
0610           size_t __u,
0611           _UIntType __d,
0612           size_t __s,
0613           _UIntType __b,
0614           size_t __t,
0615           _UIntType __c,
0616           size_t __l,
0617           _UIntType __f>
0618 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
0619     _UIntType,
0620     __w,
0621     __n,
0622     __m,
0623     __r,
0624     __a,
0625     __u,
0626     __d,
0627     __s,
0628     __b,
0629     __t,
0630     __c,
0631     __l,
0632     __f>::result_type
0633     mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
0634 
0635 template <class _UIntType,
0636           size_t __w,
0637           size_t __n,
0638           size_t __m,
0639           size_t __r,
0640           _UIntType __a,
0641           size_t __u,
0642           _UIntType __d,
0643           size_t __s,
0644           _UIntType __b,
0645           size_t __t,
0646           _UIntType __c,
0647           size_t __l,
0648           _UIntType __f>
0649 void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(
0650     result_type __sd) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2
0651   __x_[0] = __sd & _Max;
0652   for (size_t __i = 1; __i < __n; ++__i)
0653     __x_[__i] = (__f * (__x_[__i - 1] ^ __rshift<__w - 2>(__x_[__i - 1])) + __i) & _Max;
0654   __i_ = 0;
0655 }
0656 
0657 template <class _UIntType,
0658           size_t __w,
0659           size_t __n,
0660           size_t __m,
0661           size_t __r,
0662           _UIntType __a,
0663           size_t __u,
0664           _UIntType __d,
0665           size_t __s,
0666           _UIntType __b,
0667           size_t __t,
0668           _UIntType __c,
0669           size_t __l,
0670           _UIntType __f>
0671 template <class _Sseq>
0672 void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(
0673     _Sseq& __q, integral_constant<unsigned, 1>) {
0674   const unsigned __k = 1;
0675   uint32_t __ar[__n * __k];
0676   __q.generate(__ar, __ar + __n * __k);
0677   for (size_t __i = 0; __i < __n; ++__i)
0678     __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
0679   const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);
0680   __i_                     = 0;
0681   if ((__x_[0] & ~__mask) == 0) {
0682     for (size_t __i = 1; __i < __n; ++__i)
0683       if (__x_[__i] != 0)
0684         return;
0685     __x_[0] = result_type(1) << (__w - 1);
0686   }
0687 }
0688 
0689 template <class _UIntType,
0690           size_t __w,
0691           size_t __n,
0692           size_t __m,
0693           size_t __r,
0694           _UIntType __a,
0695           size_t __u,
0696           _UIntType __d,
0697           size_t __s,
0698           _UIntType __b,
0699           size_t __t,
0700           _UIntType __c,
0701           size_t __l,
0702           _UIntType __f>
0703 template <class _Sseq>
0704 void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(
0705     _Sseq& __q, integral_constant<unsigned, 2>) {
0706   const unsigned __k = 2;
0707   uint32_t __ar[__n * __k];
0708   __q.generate(__ar, __ar + __n * __k);
0709   for (size_t __i = 0; __i < __n; ++__i)
0710     __x_[__i] = static_cast<result_type>((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
0711   const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);
0712   __i_                     = 0;
0713   if ((__x_[0] & ~__mask) == 0) {
0714     for (size_t __i = 1; __i < __n; ++__i)
0715       if (__x_[__i] != 0)
0716         return;
0717     __x_[0] = result_type(1) << (__w - 1);
0718   }
0719 }
0720 
0721 template <class _UIntType,
0722           size_t __w,
0723           size_t __n,
0724           size_t __m,
0725           size_t __r,
0726           _UIntType __a,
0727           size_t __u,
0728           _UIntType __d,
0729           size_t __s,
0730           _UIntType __b,
0731           size_t __t,
0732           _UIntType __c,
0733           size_t __l,
0734           _UIntType __f>
0735 _UIntType
0736 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() {
0737   const size_t __j         = (__i_ + 1) % __n;
0738   const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);
0739   const result_type __yp   = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
0740   const size_t __k         = (__i_ + __m) % __n;
0741   __x_[__i_]               = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1));
0742   result_type __z          = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
0743   __i_                     = __j;
0744   __z ^= __lshift<__s>(__z) & __b;
0745   __z ^= __lshift<__t>(__z) & __c;
0746   return __z ^ __rshift<__l>(__z);
0747 }
0748 
0749 template <class _UInt,
0750           size_t _Wp,
0751           size_t _Np,
0752           size_t _Mp,
0753           size_t _Rp,
0754           _UInt _Ap,
0755           size_t _Up,
0756           _UInt _Dp,
0757           size_t _Sp,
0758           _UInt _Bp,
0759           size_t _Tp,
0760           _UInt _Cp,
0761           size_t _Lp,
0762           _UInt _Fp>
0763 _LIBCPP_HIDE_FROM_ABI bool
0764 operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0765            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {
0766   if (__x.__i_ == __y.__i_)
0767     return std::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
0768   if (__x.__i_ == 0 || __y.__i_ == 0) {
0769     size_t __j = std::min(_Np - __x.__i_, _Np - __y.__i_);
0770     if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, __y.__x_ + __y.__i_))
0771       return false;
0772     if (__x.__i_ == 0)
0773       return std::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
0774     return std::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
0775   }
0776   if (__x.__i_ < __y.__i_) {
0777     size_t __j = _Np - __y.__i_;
0778     if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), __y.__x_ + __y.__i_))
0779       return false;
0780     if (!std::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, __y.__x_))
0781       return false;
0782     return std::equal(__x.__x_, __x.__x_ + __x.__i_, __y.__x_ + (_Np - (__x.__i_ + __j)));
0783   }
0784   size_t __j = _Np - __x.__i_;
0785   if (!std::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), __x.__x_ + __x.__i_))
0786     return false;
0787   if (!std::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, __x.__x_))
0788     return false;
0789   return std::equal(__y.__x_, __y.__x_ + __y.__i_, __x.__x_ + (_Np - (__y.__i_ + __j)));
0790 }
0791 
0792 template <class _UInt,
0793           size_t _Wp,
0794           size_t _Np,
0795           size_t _Mp,
0796           size_t _Rp,
0797           _UInt _Ap,
0798           size_t _Up,
0799           _UInt _Dp,
0800           size_t _Sp,
0801           _UInt _Bp,
0802           size_t _Tp,
0803           _UInt _Cp,
0804           size_t _Lp,
0805           _UInt _Fp>
0806 inline _LIBCPP_HIDE_FROM_ABI bool
0807 operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
0808            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {
0809   return !(__x == __y);
0810 }
0811 
0812 template <class _CharT,
0813           class _Traits,
0814           class _UInt,
0815           size_t _Wp,
0816           size_t _Np,
0817           size_t _Mp,
0818           size_t _Rp,
0819           _UInt _Ap,
0820           size_t _Up,
0821           _UInt _Dp,
0822           size_t _Sp,
0823           _UInt _Bp,
0824           size_t _Tp,
0825           _UInt _Cp,
0826           size_t _Lp,
0827           _UInt _Fp>
0828 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0829 operator<<(basic_ostream<_CharT, _Traits>& __os,
0830            const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {
0831   __save_flags<_CharT, _Traits> __lx(__os);
0832   typedef basic_ostream<_CharT, _Traits> _Ostream;
0833   __os.flags(_Ostream::dec | _Ostream::left);
0834   _CharT __sp = __os.widen(' ');
0835   __os.fill(__sp);
0836   __os << __x.__x_[__x.__i_];
0837   for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
0838     __os << __sp << __x.__x_[__j];
0839   for (size_t __j = 0; __j < __x.__i_; ++__j)
0840     __os << __sp << __x.__x_[__j];
0841   return __os;
0842 }
0843 
0844 template <class _CharT,
0845           class _Traits,
0846           class _UInt,
0847           size_t _Wp,
0848           size_t _Np,
0849           size_t _Mp,
0850           size_t _Rp,
0851           _UInt _Ap,
0852           size_t _Up,
0853           _UInt _Dp,
0854           size_t _Sp,
0855           _UInt _Bp,
0856           size_t _Tp,
0857           _UInt _Cp,
0858           size_t _Lp,
0859           _UInt _Fp>
0860 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0861 operator>>(basic_istream<_CharT, _Traits>& __is,
0862            mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {
0863   __save_flags<_CharT, _Traits> __lx(__is);
0864   typedef basic_istream<_CharT, _Traits> _Istream;
0865   __is.flags(_Istream::dec | _Istream::skipws);
0866   _UInt __t[_Np];
0867   for (size_t __i = 0; __i < _Np; ++__i)
0868     __is >> __t[__i];
0869   if (!__is.fail()) {
0870     for (size_t __i = 0; __i < _Np; ++__i)
0871       __x.__x_[__i] = __t[__i];
0872     __x.__i_ = 0;
0873   }
0874   return __is;
0875 }
0876 
0877 typedef mersenne_twister_engine<
0878     uint_fast32_t,
0879     32,
0880     624,
0881     397,
0882     31,
0883     0x9908b0df,
0884     11,
0885     0xffffffff,
0886     7,
0887     0x9d2c5680,
0888     15,
0889     0xefc60000,
0890     18,
0891     1812433253>
0892     mt19937;
0893 typedef mersenne_twister_engine<
0894     uint_fast64_t,
0895     64,
0896     312,
0897     156,
0898     31,
0899     0xb5026f5aa96619e9ULL,
0900     29,
0901     0x5555555555555555ULL,
0902     17,
0903     0x71d67fffeda60000ULL,
0904     37,
0905     0xfff7eee000000000ULL,
0906     43,
0907     6364136223846793005ULL>
0908     mt19937_64;
0909 
0910 _LIBCPP_END_NAMESPACE_STD
0911 
0912 _LIBCPP_POP_MACROS
0913 
0914 #endif // _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H