aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2007-10-19 17:36:03 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2007-10-19 17:36:03 +0000
commit23e8722aedfa0fbde8325a8bc5ca3394ff03d13d (patch)
treef028988e1876fa0c798875833a06f8c50550b092
parent3c167a8bbb2e672462ab292668300c39d53c3713 (diff)
downloadgcc-23e8722aedfa0fbde8325a8bc5ca3394ff03d13d.zip
gcc-23e8722aedfa0fbde8325a8bc5ca3394ff03d13d.tar.gz
gcc-23e8722aedfa0fbde8325a8bc5ca3394ff03d13d.tar.bz2
re PR libstdc++/33815 (tr1::uniform_int isn't uniform)
2007-10-19 Paolo Carlini <pcarlini@suse.de> PR libstdc++/33815 * include/tr1_impl/random (uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type, result_type, true_type)): Avoid the modulo (which uses the low-order bits). From-SVN: r129493
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/tr1_impl/random6
2 files changed, 13 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b12b8b3..b4f58ac 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,13 @@
2007-10-19 Paolo Carlini <pcarlini@suse.de>
+ PR libstdc++/33815
+ * include/tr1_impl/random
+ (uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type,
+ result_type, true_type)): Avoid the modulo (which uses the low-order
+ bits).
+
+2007-10-19 Paolo Carlini <pcarlini@suse.de>
+
* include/bits/stl_algobase.h (struct __cm_assign,
struct __copy_move, struct __copy_move_backward, move,
move_backward): Add.
diff --git a/libstdc++-v3/include/tr1_impl/random b/libstdc++-v3/include/tr1_impl/random
index e855307..f44b17f 100644
--- a/libstdc++-v3/include/tr1_impl/random
+++ b/libstdc++-v3/include/tr1_impl/random
@@ -1605,9 +1605,13 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
_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<typename
_UniformRandomNumberGenerator::result_type>::__type __utype;
- return result_type(__utype(__urng()) % (__max - __min + 1)) + __min;
+ return result_type((__max - __min + 1.0L) * __utype(__urng())
+ / (__utype(__urng.max())
+ - __utype(__urng.min()) + 1.0L)) + __min;
}
template<typename _UniformRandomNumberGenerator>