https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86880
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- This would fix the equality operator to correctly compare rotated states: --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -601,8 +601,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator==(const mersenne_twister_engine& __lhs, const mersenne_twister_engine& __rhs) - { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x) - && __lhs._M_p == __rhs._M_p); } + { + const _UIntType* const __lx = __lhs._M_x; + const _UIntType* const __rx = __rhs._M_x; + size_t __lp = __lhs._M_p % state_size; + size_t __rp = __rhs._M_p % state_size; + size_t __n1, __n2; + if (__lp > __rp) + { + __n1 = state_size - __lp; + __n2 = __lp - __rp; + } + else + { + __n1 = state_size - __rp; + __n2 = __rp - __lp; + } + if (!std::equal(__lx + __lp, __lx + __lp + __n1, __rx + __rp)) + return false; + if (__n1 == state_size) // i.e. __lhs._M_p == 0 && __rhs._M_p == 0 + return true; + __lp = (__lp + __n1) % state_size; + __rp = (__rp + __n1) % state_size; + if (!std::equal(__lx + __lp, __lx + __lp + __n2, __rx + __rp)) + return false; + __lp = (__lp + __n2) % state_size; + __rp = (__rp + __n2) % state_size; + size_t __n3 = state_size - __n1 - __n2; + if (!std::equal(__lx + __lp, __lx + __lp + __n3, __rx + __rp)) + return false; + return true; + } /** * @brief Inserts the current state of a % mersenne_twister_engine But the testcase above still fails, because mteB and mteA have different content in the array, even though they produce the same sequence of numbers.