chromium/third_party/libc++/src/include/__random/mersenne_twister_engine.h

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H
#define _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H

#include <__algorithm/equal.h>
#include <__algorithm/min.h>
#include <__config>
#include <__random/is_seed_sequence.h>
#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <limits>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

_LIBCPP_PUSH_MACROS
#include <__undef_macros>

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;

template <class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI bool
operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);

template <class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI bool
operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);

template <class _CharT,
          class _Traits,
          class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);

template <class _CharT,
          class _Traits,
          class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine {};

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const size_t
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::
        initialization_multiplier;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
    _UIntType,
    __w,
    __n,
    __m,
    __r,
    __a,
    __u,
    __d,
    __s,
    __b,
    __t,
    __c,
    __l,
    __f>::result_type
    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(
    result_type __sd) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK {}

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
template <class _Sseq>
void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(
    _Sseq& __q, integral_constant<unsigned, 1>) {}

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
template <class _Sseq>
void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(
    _Sseq& __q, integral_constant<unsigned, 2>) {}

template <class _UIntType,
          size_t __w,
          size_t __n,
          size_t __m,
          size_t __r,
          _UIntType __a,
          size_t __u,
          _UIntType __d,
          size_t __s,
          _UIntType __b,
          size_t __t,
          _UIntType __c,
          size_t __l,
          _UIntType __f>
_UIntType
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() {}

template <class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI bool
operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {}

template <class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
inline _LIBCPP_HIDE_FROM_ABI bool
operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {}

template <class _CharT,
          class _Traits,
          class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {}

template <class _CharT,
          class _Traits,
          class _UInt,
          size_t _Wp,
          size_t _Np,
          size_t _Mp,
          size_t _Rp,
          _UInt _Ap,
          size_t _Up,
          _UInt _Dp,
          size_t _Sp,
          _UInt _Bp,
          size_t _Tp,
          _UInt _Cp,
          size_t _Lp,
          _UInt _Fp>
_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {}

mt19937;
mt19937_64;

_LIBCPP_END_NAMESPACE_STD

_LIBCPP_POP_MACROS

#endif // _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H