https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118665
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-16 branch has been updated by Tomasz Kaminski <[email protected]>: https://gcc.gnu.org/g:04c3e1efd4917e9cc32f7e413e8ffdce65b5aa44 commit r16-9620-g04c3e1efd4917e9cc32f7e413e8ffdce65b5aa44 Author: Tomasz KamiÅski <[email protected]> Date: Mon Jul 27 16:39:46 2026 +0200 libstdc++: Handle generators with non-zero min in uniform_int_distribution [PR118665] The commit r11-3757-g98c37d3bacbb2f that introduced Lemire's algorithm in uniform_int_distribution, assumed that any engine that generates range of size 2^32 or 2^64, returns a range starting from zero. While this is true for all standard providede engines, it may not be true for user provided range. In such case the produced output is no longer uniform: testDiscreteDist was failing for such engine. This patch simply substract __min (_Urbg::min()) from the generated number (__g()). As this value is compile time constant, this has no performance impact for generators producing ranges starting from zero. PR libstdc++/118665 libstdc++-v3/ChangeLog: * include/bits/uniform_int_dist.h (uniform_int_distribution::_S_nd): Substract __min (_Urbg::min()) from each generator invocation. * testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc: Add testDiscreteDist for shifted (with non-zero min()) engine. Reviewed-by: Jonathan Wakely <[email protected]> Signed-off-by: Tomasz KamiÅski <[email protected]> (cherry picked from commit 9d93ec2ac1b13ab09ca80bf0c684cb035e36a431)
