This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/33815] tr1::uniform_int isn't uniform



------- Comment #5 from pcarlini at suse dot de  2007-10-19 10:49 -------
To wit, this kind of change, you can certainly apply it to the 4.2.1 headers
as-is:

Index: random
===================================================================
--- random      (revision 129456)
+++ random      (working copy)
@@ -1607,7 +1607,8 @@
         {
          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())
+                            / (__urng.max() + 1.0L)) + __min;
        }

       template<typename _UniformRandomNumberGenerator>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33815


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]