1 /* test_mt19937.cpp
2 *
3 * Copyright Steven Watanabe 2011
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 * $Id$
9 *
10 */
11
12 #include <boost/random/mersenne_twister.hpp>
13 #include <algorithm>
14 #include <vector>
15 #include <boost/cstdint.hpp>
16
17 #define BOOST_RANDOM_URNG boost::random::mt19937
18
19 #define BOOST_RANDOM_SEED_WORDS 624
20
21 // validation by experiment from mt19937.c
22 #define BOOST_RANDOM_VALIDATION_VALUE 4123659995U
23 #define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 666528879U
24 #define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 3408548740U
25 #define BOOST_RANDOM_DISCARD_COUNT1 9307
26 #define BOOST_RANDOM_DISCARD_COUNT2 20000000
27 #define BOOST_RANDOM_DISCARD_MAX
28
29 #define BOOST_RANDOM_GENERATE_VALUES { 0xD091BB5CU, 0x22AE9EF6U, 0xE7E1FAEEU, 0xD5C31F79U }
30
31 #include "test_generator.ipp"
32
33 struct seed_seq_0 {
34 template<class It>
generateseed_seq_035 void generate(It begin, It end) const {
36 std::fill(begin, end, boost::uint32_t(0));
37 }
38 };
39
40 struct seed_seq_1 {
41 template<class It>
generateseed_seq_142 void generate(It begin, It end) const {
43 std::fill(begin, end, boost::uint32_t(0));
44 *(end - 1) = 1;
45 }
46 };
47
BOOST_AUTO_TEST_CASE(test_special_seed)48 BOOST_AUTO_TEST_CASE(test_special_seed) {
49 {
50 seed_seq_1 seed;
51 std::vector<boost::uint32_t> vec(624);
52 seed.generate(vec.begin(), vec.end());
53
54 std::vector<boost::uint32_t>::iterator it = vec.begin();
55 boost::mt19937 gen1(it, vec.end());
56 BOOST_CHECK_EQUAL(gen1(), 0u);
57 BOOST_CHECK_EQUAL(gen1(), 0u);
58
59 boost::mt19937 gen2(seed);
60 BOOST_CHECK_EQUAL(gen2(), 0u);
61 BOOST_CHECK_EQUAL(gen2(), 0u);
62
63 BOOST_CHECK_EQUAL(gen1, gen2);
64 }
65 {
66 seed_seq_0 seed;
67 std::vector<boost::uint32_t> vec(624);
68 seed.generate(vec.begin(), vec.end());
69
70 std::vector<boost::uint32_t>::iterator it = vec.begin();
71 boost::mt19937 gen1(it, vec.end());
72 BOOST_CHECK_EQUAL(gen1(), 1141379330u);
73 BOOST_CHECK_EQUAL(gen1(), 0u);
74
75 boost::mt19937 gen2(seed);
76 BOOST_CHECK_EQUAL(gen2(), 1141379330u);
77 BOOST_CHECK_EQUAL(gen2(), 0u);
78
79 BOOST_CHECK_EQUAL(gen1, gen2);
80 }
81 }
82