2
0
mirror of https://github.com/boostorg/random.git synced 2026-01-19 04:22:17 +00:00

Fix typo in seed_seq which caused the wrong result when the output sequence is shorter than the input sequence.

This commit is contained in:
Steven Watanabe
2017-10-09 09:54:10 -06:00
parent ab411acba3
commit 85ffca64e6
2 changed files with 18 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ public:
& mask);
r3 = r3 ^ (r3 >> 27);
r3 = (r3 * 1566083941u) & mask;
value_type r4 = static_cast<value_type>(r3 - k%m);
value_type r4 = static_cast<value_type>(r3 - k%n);
*(first + (k+p)%n) ^= r3;
*(first + (k+q)%n) ^= r4;
*(first + k%n) = r4;

View File

@@ -111,3 +111,20 @@ BOOST_AUTO_TEST_CASE(test_seed_seq) {
&param[0], &param[0] + 4, &expected_param[0], &expected_param[0] + 4);
#endif
}
BOOST_AUTO_TEST_CASE(test_seed_seq_short_output) {
boost::uint32_t store32[2];
boost::uint32_t expected_short[2] = {
4149590228u,
3175758659u
};
std::vector<int> data = list_of(2)(3)(4)(5);
boost::random::seed_seq seq(data);
seq.generate(&store32[0], &store32[0] + 2);
BOOST_CHECK_EQUAL_COLLECTIONS(
&store32[0], &store32[0] + 2, &expected_short[0], &expected_short[0] + 2);
}