https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118665
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Tomasz Kaminski <[email protected]>: https://gcc.gnu.org/g:99266eead94c8aca7faa1e06d886c2f4abdbb1ed commit r17-3781-g99266eead94c8aca7faa1e06d886c2f4abdbb1ed 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]>
