Path: blob/main/contrib/llvm-project/libcxx/include/__random/mersenne_twister_engine.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H9#define _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H1011#include <__algorithm/equal.h>12#include <__algorithm/min.h>13#include <__config>14#include <__random/is_seed_sequence.h>15#include <cstddef>16#include <cstdint>17#include <iosfwd>18#include <limits>1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21# pragma GCC system_header22#endif2324_LIBCPP_PUSH_MACROS25#include <__undef_macros>2627_LIBCPP_BEGIN_NAMESPACE_STD2829template <class _UIntType,30size_t __w,31size_t __n,32size_t __m,33size_t __r,34_UIntType __a,35size_t __u,36_UIntType __d,37size_t __s,38_UIntType __b,39size_t __t,40_UIntType __c,41size_t __l,42_UIntType __f>43class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;4445template <class _UInt,46size_t _Wp,47size_t _Np,48size_t _Mp,49size_t _Rp,50_UInt _Ap,51size_t _Up,52_UInt _Dp,53size_t _Sp,54_UInt _Bp,55size_t _Tp,56_UInt _Cp,57size_t _Lp,58_UInt _Fp>59_LIBCPP_HIDE_FROM_ABI bool60operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,61const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);6263template <class _UInt,64size_t _Wp,65size_t _Np,66size_t _Mp,67size_t _Rp,68_UInt _Ap,69size_t _Up,70_UInt _Dp,71size_t _Sp,72_UInt _Bp,73size_t _Tp,74_UInt _Cp,75size_t _Lp,76_UInt _Fp>77_LIBCPP_HIDE_FROM_ABI bool78operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,79const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);8081template <class _CharT,82class _Traits,83class _UInt,84size_t _Wp,85size_t _Np,86size_t _Mp,87size_t _Rp,88_UInt _Ap,89size_t _Up,90_UInt _Dp,91size_t _Sp,92_UInt _Bp,93size_t _Tp,94_UInt _Cp,95size_t _Lp,96_UInt _Fp>97_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&98operator<<(basic_ostream<_CharT, _Traits>& __os,99const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);100101template <class _CharT,102class _Traits,103class _UInt,104size_t _Wp,105size_t _Np,106size_t _Mp,107size_t _Rp,108_UInt _Ap,109size_t _Up,110_UInt _Dp,111size_t _Sp,112_UInt _Bp,113size_t _Tp,114_UInt _Cp,115size_t _Lp,116_UInt _Fp>117_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&118operator>>(basic_istream<_CharT, _Traits>& __is,119mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);120121template <class _UIntType,122size_t __w,123size_t __n,124size_t __m,125size_t __r,126_UIntType __a,127size_t __u,128_UIntType __d,129size_t __s,130_UIntType __b,131size_t __t,132_UIntType __c,133size_t __l,134_UIntType __f>135class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine {136public:137// types138typedef _UIntType result_type;139140private:141result_type __x_[__n];142size_t __i_;143144static_assert(0 < __m, "mersenne_twister_engine invalid parameters");145static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");146static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;147static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");148static_assert(2 <= __w, "mersenne_twister_engine invalid parameters");149static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");150static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");151static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");152static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");153static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");154155public:156static _LIBCPP_CONSTEXPR const result_type _Min = 0;157static _LIBCPP_CONSTEXPR const result_type _Max =158__w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1);159static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");160static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");161static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");162static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");163static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");164static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");165166// engine characteristics167static _LIBCPP_CONSTEXPR const size_t word_size = __w;168static _LIBCPP_CONSTEXPR const size_t state_size = __n;169static _LIBCPP_CONSTEXPR const size_t shift_size = __m;170static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;171static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;172static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;173static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;174static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;175static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;176static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;177static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;178static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;179static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;180_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }181_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }182static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;183184// constructors and seeding functions185#ifndef _LIBCPP_CXX03_LANG186_LIBCPP_HIDE_FROM_ABI mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}187_LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }188#else189_LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd = default_seed) { seed(__sd); }190#endif191template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>192_LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(_Sseq& __q) {193seed(__q);194}195_LIBCPP_HIDE_FROM_ABI void seed(result_type __sd = default_seed);196template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>197_LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) {198__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());199}200201// generating functions202_LIBCPP_HIDE_FROM_ABI result_type operator()();203_LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) {204for (; __z; --__z)205operator()();206}207208template <class _UInt,209size_t _Wp,210size_t _Np,211size_t _Mp,212size_t _Rp,213_UInt _Ap,214size_t _Up,215_UInt _Dp,216size_t _Sp,217_UInt _Bp,218size_t _Tp,219_UInt _Cp,220size_t _Lp,221_UInt _Fp>222friend bool operator==(223const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,224const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);225226template <class _UInt,227size_t _Wp,228size_t _Np,229size_t _Mp,230size_t _Rp,231_UInt _Ap,232size_t _Up,233_UInt _Dp,234size_t _Sp,235_UInt _Bp,236size_t _Tp,237_UInt _Cp,238size_t _Lp,239_UInt _Fp>240friend bool operator!=(241const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,242const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);243244template <class _CharT,245class _Traits,246class _UInt,247size_t _Wp,248size_t _Np,249size_t _Mp,250size_t _Rp,251_UInt _Ap,252size_t _Up,253_UInt _Dp,254size_t _Sp,255_UInt _Bp,256size_t _Tp,257_UInt _Cp,258size_t _Lp,259_UInt _Fp>260friend basic_ostream<_CharT, _Traits>& operator<<(261basic_ostream<_CharT, _Traits>& __os,262const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);263264template <class _CharT,265class _Traits,266class _UInt,267size_t _Wp,268size_t _Np,269size_t _Mp,270size_t _Rp,271_UInt _Ap,272size_t _Up,273_UInt _Dp,274size_t _Sp,275_UInt _Bp,276size_t _Tp,277_UInt _Cp,278size_t _Lp,279_UInt _Fp>280friend basic_istream<_CharT, _Traits>&281operator>>(basic_istream<_CharT, _Traits>& __is,282mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);283284private:285template <class _Sseq>286_LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 1>);287template <class _Sseq>288_LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 2>);289290template <size_t __count,291__enable_if_t<__count< __w, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) {292return (__x << __count) & _Max;293}294295template <size_t __count, __enable_if_t<(__count >= __w), int> = 0>296_LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type) {297return result_type(0);298}299300template <size_t __count,301__enable_if_t<__count< _Dt, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type __x) {302return __x >> __count;303}304305template <size_t __count, __enable_if_t<(__count >= _Dt), int> = 0>306_LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type) {307return result_type(0);308}309};310311template <class _UIntType,312size_t __w,313size_t __n,314size_t __m,315size_t __r,316_UIntType __a,317size_t __u,318_UIntType __d,319size_t __s,320_UIntType __b,321size_t __t,322_UIntType __c,323size_t __l,324_UIntType __f>325_LIBCPP_CONSTEXPR const size_t326mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;327328template <class _UIntType,329size_t __w,330size_t __n,331size_t __m,332size_t __r,333_UIntType __a,334size_t __u,335_UIntType __d,336size_t __s,337_UIntType __b,338size_t __t,339_UIntType __c,340size_t __l,341_UIntType __f>342_LIBCPP_CONSTEXPR const size_t343mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;344345template <class _UIntType,346size_t __w,347size_t __n,348size_t __m,349size_t __r,350_UIntType __a,351size_t __u,352_UIntType __d,353size_t __s,354_UIntType __b,355size_t __t,356_UIntType __c,357size_t __l,358_UIntType __f>359_LIBCPP_CONSTEXPR const size_t360mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;361362template <class _UIntType,363size_t __w,364size_t __n,365size_t __m,366size_t __r,367_UIntType __a,368size_t __u,369_UIntType __d,370size_t __s,371_UIntType __b,372size_t __t,373_UIntType __c,374size_t __l,375_UIntType __f>376_LIBCPP_CONSTEXPR const size_t377mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;378379template <class _UIntType,380size_t __w,381size_t __n,382size_t __m,383size_t __r,384_UIntType __a,385size_t __u,386_UIntType __d,387size_t __s,388_UIntType __b,389size_t __t,390_UIntType __c,391size_t __l,392_UIntType __f>393_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<394_UIntType,395__w,396__n,397__m,398__r,399__a,400__u,401__d,402__s,403__b,404__t,405__c,406__l,407__f>::result_type408mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;409410template <class _UIntType,411size_t __w,412size_t __n,413size_t __m,414size_t __r,415_UIntType __a,416size_t __u,417_UIntType __d,418size_t __s,419_UIntType __b,420size_t __t,421_UIntType __c,422size_t __l,423_UIntType __f>424_LIBCPP_CONSTEXPR const size_t425mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;426427template <class _UIntType,428size_t __w,429size_t __n,430size_t __m,431size_t __r,432_UIntType __a,433size_t __u,434_UIntType __d,435size_t __s,436_UIntType __b,437size_t __t,438_UIntType __c,439size_t __l,440_UIntType __f>441_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<442_UIntType,443__w,444__n,445__m,446__r,447__a,448__u,449__d,450__s,451__b,452__t,453__c,454__l,455__f>::result_type456mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;457458template <class _UIntType,459size_t __w,460size_t __n,461size_t __m,462size_t __r,463_UIntType __a,464size_t __u,465_UIntType __d,466size_t __s,467_UIntType __b,468size_t __t,469_UIntType __c,470size_t __l,471_UIntType __f>472_LIBCPP_CONSTEXPR const size_t473mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;474475template <class _UIntType,476size_t __w,477size_t __n,478size_t __m,479size_t __r,480_UIntType __a,481size_t __u,482_UIntType __d,483size_t __s,484_UIntType __b,485size_t __t,486_UIntType __c,487size_t __l,488_UIntType __f>489_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<490_UIntType,491__w,492__n,493__m,494__r,495__a,496__u,497__d,498__s,499__b,500__t,501__c,502__l,503__f>::result_type504mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;505506template <class _UIntType,507size_t __w,508size_t __n,509size_t __m,510size_t __r,511_UIntType __a,512size_t __u,513_UIntType __d,514size_t __s,515_UIntType __b,516size_t __t,517_UIntType __c,518size_t __l,519_UIntType __f>520_LIBCPP_CONSTEXPR const size_t521mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;522523template <class _UIntType,524size_t __w,525size_t __n,526size_t __m,527size_t __r,528_UIntType __a,529size_t __u,530_UIntType __d,531size_t __s,532_UIntType __b,533size_t __t,534_UIntType __c,535size_t __l,536_UIntType __f>537_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<538_UIntType,539__w,540__n,541__m,542__r,543__a,544__u,545__d,546__s,547__b,548__t,549__c,550__l,551__f>::result_type552mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;553554template <class _UIntType,555size_t __w,556size_t __n,557size_t __m,558size_t __r,559_UIntType __a,560size_t __u,561_UIntType __d,562size_t __s,563_UIntType __b,564size_t __t,565_UIntType __c,566size_t __l,567_UIntType __f>568_LIBCPP_CONSTEXPR const size_t569mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;570571template <class _UIntType,572size_t __w,573size_t __n,574size_t __m,575size_t __r,576_UIntType __a,577size_t __u,578_UIntType __d,579size_t __s,580_UIntType __b,581size_t __t,582_UIntType __c,583size_t __l,584_UIntType __f>585_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<586_UIntType,587__w,588__n,589__m,590__r,591__a,592__u,593__d,594__s,595__b,596__t,597__c,598__l,599__f>::result_type600mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::601initialization_multiplier;602603template <class _UIntType,604size_t __w,605size_t __n,606size_t __m,607size_t __r,608_UIntType __a,609size_t __u,610_UIntType __d,611size_t __s,612_UIntType __b,613size_t __t,614_UIntType __c,615size_t __l,616_UIntType __f>617_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<618_UIntType,619__w,620__n,621__m,622__r,623__a,624__u,625__d,626__s,627__b,628__t,629__c,630__l,631__f>::result_type632mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;633634template <class _UIntType,635size_t __w,636size_t __n,637size_t __m,638size_t __r,639_UIntType __a,640size_t __u,641_UIntType __d,642size_t __s,643_UIntType __b,644size_t __t,645_UIntType __c,646size_t __l,647_UIntType __f>648void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(649result_type __sd) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2650__x_[0] = __sd & _Max;651for (size_t __i = 1; __i < __n; ++__i)652__x_[__i] = (__f * (__x_[__i - 1] ^ __rshift<__w - 2>(__x_[__i - 1])) + __i) & _Max;653__i_ = 0;654}655656template <class _UIntType,657size_t __w,658size_t __n,659size_t __m,660size_t __r,661_UIntType __a,662size_t __u,663_UIntType __d,664size_t __s,665_UIntType __b,666size_t __t,667_UIntType __c,668size_t __l,669_UIntType __f>670template <class _Sseq>671void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(672_Sseq& __q, integral_constant<unsigned, 1>) {673const unsigned __k = 1;674uint32_t __ar[__n * __k];675__q.generate(__ar, __ar + __n * __k);676for (size_t __i = 0; __i < __n; ++__i)677__x_[__i] = static_cast<result_type>(__ar[__i] & _Max);678const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);679__i_ = 0;680if ((__x_[0] & ~__mask) == 0) {681for (size_t __i = 1; __i < __n; ++__i)682if (__x_[__i] != 0)683return;684__x_[0] = result_type(1) << (__w - 1);685}686}687688template <class _UIntType,689size_t __w,690size_t __n,691size_t __m,692size_t __r,693_UIntType __a,694size_t __u,695_UIntType __d,696size_t __s,697_UIntType __b,698size_t __t,699_UIntType __c,700size_t __l,701_UIntType __f>702template <class _Sseq>703void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(704_Sseq& __q, integral_constant<unsigned, 2>) {705const unsigned __k = 2;706uint32_t __ar[__n * __k];707__q.generate(__ar, __ar + __n * __k);708for (size_t __i = 0; __i < __n; ++__i)709__x_[__i] = static_cast<result_type>((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);710const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);711__i_ = 0;712if ((__x_[0] & ~__mask) == 0) {713for (size_t __i = 1; __i < __n; ++__i)714if (__x_[__i] != 0)715return;716__x_[0] = result_type(1) << (__w - 1);717}718}719720template <class _UIntType,721size_t __w,722size_t __n,723size_t __m,724size_t __r,725_UIntType __a,726size_t __u,727_UIntType __d,728size_t __s,729_UIntType __b,730size_t __t,731_UIntType __c,732size_t __l,733_UIntType __f>734_UIntType735mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() {736const size_t __j = (__i_ + 1) % __n;737const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);738const result_type __yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);739const size_t __k = (__i_ + __m) % __n;740__x_[__i_] = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1));741result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);742__i_ = __j;743__z ^= __lshift<__s>(__z) & __b;744__z ^= __lshift<__t>(__z) & __c;745return __z ^ __rshift<__l>(__z);746}747748template <class _UInt,749size_t _Wp,750size_t _Np,751size_t _Mp,752size_t _Rp,753_UInt _Ap,754size_t _Up,755_UInt _Dp,756size_t _Sp,757_UInt _Bp,758size_t _Tp,759_UInt _Cp,760size_t _Lp,761_UInt _Fp>762_LIBCPP_HIDE_FROM_ABI bool763operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,764const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {765if (__x.__i_ == __y.__i_)766return std::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);767if (__x.__i_ == 0 || __y.__i_ == 0) {768size_t __j = std::min(_Np - __x.__i_, _Np - __y.__i_);769if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, __y.__x_ + __y.__i_))770return false;771if (__x.__i_ == 0)772return std::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);773return std::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);774}775if (__x.__i_ < __y.__i_) {776size_t __j = _Np - __y.__i_;777if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), __y.__x_ + __y.__i_))778return false;779if (!std::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, __y.__x_))780return false;781return std::equal(__x.__x_, __x.__x_ + __x.__i_, __y.__x_ + (_Np - (__x.__i_ + __j)));782}783size_t __j = _Np - __x.__i_;784if (!std::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), __x.__x_ + __x.__i_))785return false;786if (!std::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, __x.__x_))787return false;788return std::equal(__y.__x_, __y.__x_ + __y.__i_, __x.__x_ + (_Np - (__y.__i_ + __j)));789}790791template <class _UInt,792size_t _Wp,793size_t _Np,794size_t _Mp,795size_t _Rp,796_UInt _Ap,797size_t _Up,798_UInt _Dp,799size_t _Sp,800_UInt _Bp,801size_t _Tp,802_UInt _Cp,803size_t _Lp,804_UInt _Fp>805inline _LIBCPP_HIDE_FROM_ABI bool806operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,807const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {808return !(__x == __y);809}810811template <class _CharT,812class _Traits,813class _UInt,814size_t _Wp,815size_t _Np,816size_t _Mp,817size_t _Rp,818_UInt _Ap,819size_t _Up,820_UInt _Dp,821size_t _Sp,822_UInt _Bp,823size_t _Tp,824_UInt _Cp,825size_t _Lp,826_UInt _Fp>827_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&828operator<<(basic_ostream<_CharT, _Traits>& __os,829const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {830__save_flags<_CharT, _Traits> __lx(__os);831typedef basic_ostream<_CharT, _Traits> _Ostream;832__os.flags(_Ostream::dec | _Ostream::left);833_CharT __sp = __os.widen(' ');834__os.fill(__sp);835__os << __x.__x_[__x.__i_];836for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)837__os << __sp << __x.__x_[__j];838for (size_t __j = 0; __j < __x.__i_; ++__j)839__os << __sp << __x.__x_[__j];840return __os;841}842843template <class _CharT,844class _Traits,845class _UInt,846size_t _Wp,847size_t _Np,848size_t _Mp,849size_t _Rp,850_UInt _Ap,851size_t _Up,852_UInt _Dp,853size_t _Sp,854_UInt _Bp,855size_t _Tp,856_UInt _Cp,857size_t _Lp,858_UInt _Fp>859_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&860operator>>(basic_istream<_CharT, _Traits>& __is,861mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {862__save_flags<_CharT, _Traits> __lx(__is);863typedef basic_istream<_CharT, _Traits> _Istream;864__is.flags(_Istream::dec | _Istream::skipws);865_UInt __t[_Np];866for (size_t __i = 0; __i < _Np; ++__i)867__is >> __t[__i];868if (!__is.fail()) {869for (size_t __i = 0; __i < _Np; ++__i)870__x.__x_[__i] = __t[__i];871__x.__i_ = 0;872}873return __is;874}875876typedef mersenne_twister_engine<877uint_fast32_t,87832,879624,880397,88131,8820x9908b0df,88311,8840xffffffff,8857,8860x9d2c5680,88715,8880xefc60000,88918,8901812433253>891mt19937;892typedef mersenne_twister_engine<893uint_fast64_t,89464,895312,896156,89731,8980xb5026f5aa96619e9ULL,89929,9000x5555555555555555ULL,90117,9020x71d67fffeda60000ULL,90337,9040xfff7eee000000000ULL,90543,9066364136223846793005ULL>907mt19937_64;908909_LIBCPP_END_NAMESPACE_STD910911_LIBCPP_POP_MACROS912913#endif // _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H914915916