1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <random>
11
12 // template <class UIntType, size_t w, size_t n, size_t m, size_t r,
13 // UIntType a, size_t u, UIntType d, size_t s,
14 // UIntType b, size_t t, UIntType c, size_t l, UIntType f>
15 // class mersenne_twister_engine
16 // {
17 // public:
18 // // types
19 // typedef UIntType result_type;
20 //
21 // // engine characteristics
22 // static constexpr size_t word_size = w;
23 // static constexpr size_t state_size = n;
24 // static constexpr size_t shift_size = m;
25 // static constexpr size_t mask_bits = r;
26 // static constexpr result_type xor_mask = a;
27 // static constexpr size_t tempering_u = u;
28 // static constexpr result_type tempering_d = d;
29 // static constexpr size_t tempering_s = s;
30 // static constexpr result_type tempering_b = b;
31 // static constexpr size_t tempering_t = t;
32 // static constexpr result_type tempering_c = c;
33 // static constexpr size_t tempering_l = l;
34 // static constexpr result_type initialization_multiplier = f;
35 // static constexpr result_type min () { return 0; }
36 // static constexpr result_type max() { return 2^w - 1; }
37 // static constexpr result_type default_seed = 5489u;
38
39 #include <random>
40 #include <type_traits>
41 #include <cassert>
42
43 #include "test_macros.h"
44
45 template <class T>
where(const T &)46 void where(const T &) {}
47
48 void
test1()49 test1()
50 {
51 typedef std::mt19937 E;
52 static_assert((E::word_size == 32), "");
53 static_assert((E::state_size == 624), "");
54 static_assert((E::shift_size == 397), "");
55 static_assert((E::mask_bits == 31), "");
56 static_assert((E::xor_mask == 0x9908b0df), "");
57 static_assert((E::tempering_u == 11), "");
58 static_assert((E::tempering_d == 0xffffffff), "");
59 static_assert((E::tempering_s == 7), "");
60 static_assert((E::tempering_b == 0x9d2c5680), "");
61 static_assert((E::tempering_t == 15), "");
62 static_assert((E::tempering_c == 0xefc60000), "");
63 static_assert((E::tempering_l == 18), "");
64 static_assert((E::initialization_multiplier == 1812433253), "");
65 #if TEST_STD_VER >= 11
66 static_assert((E::min() == 0), "");
67 static_assert((E::max() == 0xFFFFFFFF), "");
68 #else
69 assert((E::min() == 0));
70 assert((E::max() == 0xFFFFFFFF));
71 #endif
72 static_assert((E::default_seed == 5489u), "");
73 where(E::word_size);
74 where(E::state_size);
75 where(E::shift_size);
76 where(E::mask_bits);
77 where(E::xor_mask);
78 where(E::tempering_u);
79 where(E::tempering_d);
80 where(E::tempering_s);
81 where(E::tempering_b);
82 where(E::tempering_t);
83 where(E::tempering_c);
84 where(E::tempering_l);
85 where(E::initialization_multiplier);
86 where(E::default_seed);
87 }
88
89 void
test2()90 test2()
91 {
92 typedef std::mt19937_64 E;
93 static_assert((E::word_size == 64), "");
94 static_assert((E::state_size == 312), "");
95 static_assert((E::shift_size == 156), "");
96 static_assert((E::mask_bits == 31), "");
97 static_assert((E::xor_mask == 0xb5026f5aa96619e9ull), "");
98 static_assert((E::tempering_u == 29), "");
99 static_assert((E::tempering_d == 0x5555555555555555ull), "");
100 static_assert((E::tempering_s == 17), "");
101 static_assert((E::tempering_b == 0x71d67fffeda60000ull), "");
102 static_assert((E::tempering_t == 37), "");
103 static_assert((E::tempering_c == 0xfff7eee000000000ull), "");
104 static_assert((E::tempering_l == 43), "");
105 static_assert((E::initialization_multiplier == 6364136223846793005ull), "");
106 #if TEST_STD_VER >= 11
107 static_assert((E::min() == 0), "");
108 static_assert((E::max() == 0xFFFFFFFFFFFFFFFFull), "");
109 #else
110 assert((E::min() == 0));
111 assert((E::max() == 0xFFFFFFFFFFFFFFFFull));
112 #endif
113 static_assert((E::default_seed == 5489u), "");
114 where(E::word_size);
115 where(E::state_size);
116 where(E::shift_size);
117 where(E::mask_bits);
118 where(E::xor_mask);
119 where(E::tempering_u);
120 where(E::tempering_d);
121 where(E::tempering_s);
122 where(E::tempering_b);
123 where(E::tempering_t);
124 where(E::tempering_c);
125 where(E::tempering_l);
126 where(E::initialization_multiplier);
127 where(E::default_seed);
128 }
129
main()130 int main()
131 {
132 test1();
133 test2();
134 }
135