Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60699 - in trunk: boost/uuid libs/uuid/test
From: atompkins_at_[hidden]
Date: 2010-03-18 21:44:53


Author: atompkins
Date: 2010-03-18 21:44:52 EDT (Thu, 18 Mar 2010)
New Revision: 60699
URL: http://svn.boost.org/trac/boost/changeset/60699

Log:
Fixed bug in basic_random_generator. It wasn't producing random uuids correctly.
Text files modified:
   trunk/boost/uuid/random_generator.hpp | 1 +
   trunk/libs/uuid/test/Jamfile.v2 | 2 +-
   trunk/libs/uuid/test/test_random_generator.cpp | 11 +++++++++++
   3 files changed, 13 insertions(+), 1 deletions(-)

Modified: trunk/boost/uuid/random_generator.hpp
==============================================================================
--- trunk/boost/uuid/random_generator.hpp (original)
+++ trunk/boost/uuid/random_generator.hpp 2010-03-18 21:44:52 EDT (Thu, 18 Mar 2010)
@@ -87,6 +87,7 @@
         for (uuid::iterator it=u.begin(); it!=u.end(); ++it, ++i) {
             if (i==sizeof(unsigned long)) {
                 random_value = generator();
+ i = 0;
             }
 
             *it = ((random_value >> (i*8)) & 0xFF);

Modified: trunk/libs/uuid/test/Jamfile.v2
==============================================================================
--- trunk/libs/uuid/test/Jamfile.v2 (original)
+++ trunk/libs/uuid/test/Jamfile.v2 2010-03-18 21:44:52 EDT (Thu, 18 Mar 2010)
@@ -15,7 +15,7 @@
     [ compile compile_name_generator.cpp ]
     [ compile compile_string_generator.cpp ]
     [ compile compile_random_generator.cpp ]
-
+
     # test inclucing all .hpp files in 2 translations units
     # to look for issues when using multiple translation units
     # eg. missing inline on a global functionstate is not missing

Modified: trunk/libs/uuid/test/test_random_generator.cpp
==============================================================================
--- trunk/libs/uuid/test/test_random_generator.cpp (original)
+++ trunk/libs/uuid/test/test_random_generator.cpp 2010-03-18 21:44:52 EDT (Thu, 18 Mar 2010)
@@ -56,6 +56,17 @@
     // random device
     //basic_random_generator<boost::random_device> uuid_gen5;
     //check_random_generator(uuid_gen5);
+
+ // there was a bug in basic_random_generator where it did not
+ // produce very random numbers. This checks for that bug.
+ uuid u = random_generator()();
+ if ( (u.data[4] == u.data[12]) &&
+ (u.data[5] == u.data[9] && u.data[5] == u.data[13]) &&
+ (u.data[7] == u.data[11] && u.data[7] == u.data[15]) &&
+ (u.data[10] == u.data[14]) )
+ {
+ BOOST_ERROR("basic_random_generator is not producing random uuids");
+ }
 
     return boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk