From f3be87cd22f6d46f84394c40b720a0db9d4f5cdf Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 20 Oct 2007 10:02:34 +0000 Subject: [PATCH] [multiple changes] 2007-10-20 Paolo Carlini * include/tr1/random (uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type, result_type, true_type)): Fix small thinko. 2007-10-19 Paolo Carlini PR libstdc++/33815 * include/tr1/random (uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type, result_type, true_type)): Avoid the modulo (which uses the low-order bits). From-SVN: r129507 --- libstdc++-v3/include/tr1/random | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index c97f16d2a2d7..492adfd5e74c 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -1618,10 +1618,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) result_type _M_call(_UniformRandomNumberGenerator& __urng, result_type __min, result_type __max, true_type) - { + { + // XXX Must be fixed to also work when __urng.max() - __urng.min() + // is smaller than __max - __min. typedef typename __gnu_cxx::__add_unsigned::__type __utype; - return result_type(__utype(__urng()) % (__max - __min + 1)) + __min; + return result_type((__max - __min + 1.0L) + * (__utype(__urng()) - __utype(__urng.min())) + / (__utype(__urng.max()) + - __utype(__urng.min()) + 1.0L)) + __min; } template -- 2.47.2