Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74169 - in trunk: boost/random libs/random/test
From: steven_at_[hidden]
Date: 2011-08-30 17:14:01


Author: steven_watanabe
Date: 2011-08-30 17:14:01 EDT (Tue, 30 Aug 2011)
New Revision: 74169
URL: http://svn.boost.org/trac/boost/changeset/74169

Log:
Use the right variable. Fixes #5767.
Text files modified:
   trunk/boost/random/mersenne_twister.hpp | 4 +-
   trunk/libs/random/test/test_mt19937.cpp | 53 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 55 insertions(+), 2 deletions(-)

Modified: trunk/boost/random/mersenne_twister.hpp
==============================================================================
--- trunk/boost/random/mersenne_twister.hpp (original)
+++ trunk/boost/random/mersenne_twister.hpp 2011-08-30 17:14:01 EDT (Tue, 30 Aug 2011)
@@ -159,7 +159,7 @@
 
         // fix up the state if it's all zeroes.
         if((x[0] & (~static_cast<UIntType>(0) << r)) == 0) {
- for(std::size_t j = 1; i < n; ++j) {
+ for(std::size_t j = 1; j < n; ++j) {
                 if(x[j] != 0) return;
             }
             x[0] = static_cast<UIntType>(1) << (w-1);
@@ -175,7 +175,7 @@
 
         // fix up the state if it's all zeroes.
         if((x[0] & (~static_cast<UIntType>(0) << r)) == 0) {
- for(std::size_t j = 1; i < n; ++j) {
+ for(std::size_t j = 1; j < n; ++j) {
                 if(x[j] != 0) return;
             }
             x[0] = static_cast<UIntType>(1) << (w-1);

Modified: trunk/libs/random/test/test_mt19937.cpp
==============================================================================
--- trunk/libs/random/test/test_mt19937.cpp (original)
+++ trunk/libs/random/test/test_mt19937.cpp 2011-08-30 17:14:01 EDT (Tue, 30 Aug 2011)
@@ -10,6 +10,9 @@
  */
 
 #include <boost/random/mersenne_twister.hpp>
+#include <algorithm>
+#include <vector>
+#include <boost/cstdint.hpp>
 
 #define BOOST_RANDOM_URNG boost::random::mt19937
 
@@ -23,3 +26,53 @@
 #define BOOST_RANDOM_GENERATE_VALUES { 0xD091BB5CU, 0x22AE9EF6U, 0xE7E1FAEEU, 0xD5C31F79U }
 
 #include "test_generator.ipp"
+
+struct seed_seq_0 {
+ template<class It>
+ void generate(It begin, It end) const {
+ std::fill(begin, end, boost::uint32_t(0));
+ }
+};
+
+struct seed_seq_1 {
+ template<class It>
+ void generate(It begin, It end) const {
+ std::fill(begin, end, boost::uint32_t(0));
+ *(end - 1) = 1;
+ }
+};
+
+BOOST_AUTO_TEST_CASE(test_special_seed) {
+ {
+ seed_seq_1 seed;
+ std::vector<boost::uint32_t> vec(624);
+ seed.generate(vec.begin(), vec.end());
+
+ std::vector<boost::uint32_t>::iterator it = vec.begin();
+ boost::mt19937 gen1(it, vec.end());
+ BOOST_CHECK_EQUAL(gen1(), 0);
+ BOOST_CHECK_EQUAL(gen1(), 0);
+
+ boost::mt19937 gen2(seed);
+ BOOST_CHECK_EQUAL(gen2(), 0);
+ BOOST_CHECK_EQUAL(gen2(), 0);
+
+ BOOST_CHECK_EQUAL(gen1, gen2);
+ }
+ {
+ seed_seq_0 seed;
+ std::vector<boost::uint32_t> vec(624);
+ seed.generate(vec.begin(), vec.end());
+
+ std::vector<boost::uint32_t>::iterator it = vec.begin();
+ boost::mt19937 gen1(it, vec.end());
+ BOOST_CHECK_EQUAL(gen1(), 1141379330u);
+ BOOST_CHECK_EQUAL(gen1(), 0);
+
+ boost::mt19937 gen2(seed);
+ BOOST_CHECK_EQUAL(gen2(), 1141379330u);
+ BOOST_CHECK_EQUAL(gen2(), 0);
+
+ BOOST_CHECK_EQUAL(gen1, gen2);
+ }
+}


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