https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97311
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:3ee44d4c518d61c6bbf75fcf280edc6ce5326ce0 commit r11-3759-g3ee44d4c518d61c6bbf75fcf280edc6ce5326ce0 Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Oct 9 16:10:31 2020 +0100 libstdc++: Fix incorrect results in std::seed_seq::generate [PR 97311] This ensures that intermediate results are done in uint32_t values, meeting the requirement for operations to be done modulo 2^32. If the target doesn't define __UINT32_TYPE__ then substitute uint32_t with a class type that uses uint_least32_t and masks the value to UINT32_MAX. I've also split the first loop that goes from k=0 to k<m into three loops, for k=0, [1,s] and [s+1,m). This avoids branching for those three cases in the body of the loop, and also avoids the concerns in PR 94823 regarding the k-1 index when k==0. libstdc++-v3/ChangeLog: PR libstdc++/97311 * include/bits/random.tcc (seed_seq::generate): Use uint32_t for calculations. Also split the first loop into three loops to avoid branching on k on every iteration, resolving PR 94823. * testsuite/26_numerics/random/seed_seq/97311.cc: New test. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-erro line number.