blob: 331d3c51119ffcaad55da38cda0ad8b8bb3fb4c8 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
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;
Howard Hinnanta0eaf602010-08-22 00:42:21 +000020//
Howard Hinnant3e519522010-05-11 19:42:16 +000021// // 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
Howard Hinnant16694b52012-12-12 21:14:28 +000043template <class _Tp>
44void where(const _Tp &) {}
45
Howard Hinnant3e519522010-05-11 19:42:16 +000046void
47test1()
48{
49 typedef std::mt19937 E;
50 static_assert((E::word_size == 32), "");
51 static_assert((E::state_size == 624), "");
52 static_assert((E::shift_size == 397), "");
53 static_assert((E::mask_bits == 31), "");
54 static_assert((E::xor_mask == 0x9908b0df), "");
55 static_assert((E::tempering_u == 11), "");
56 static_assert((E::tempering_d == 0xffffffff), "");
57 static_assert((E::tempering_s == 7), "");
58 static_assert((E::tempering_b == 0x9d2c5680), "");
59 static_assert((E::tempering_t == 15), "");
60 static_assert((E::tempering_c == 0xefc60000), "");
61 static_assert((E::tempering_l == 18), "");
62 static_assert((E::initialization_multiplier == 1812433253), "");
63 /*static_*/assert((E::min() == 0)/*, ""*/);
64 /*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/);
65 static_assert((E::default_seed == 5489u), "");
Howard Hinnant16694b52012-12-12 21:14:28 +000066 where(E::word_size);
67 where(E::state_size);
68 where(E::shift_size);
69 where(E::mask_bits);
70 where(E::xor_mask);
71 where(E::tempering_u);
72 where(E::tempering_d);
73 where(E::tempering_s);
74 where(E::tempering_b);
75 where(E::tempering_t);
76 where(E::tempering_c);
77 where(E::tempering_l);
78 where(E::initialization_multiplier);
79 where(E::default_seed);
Howard Hinnant3e519522010-05-11 19:42:16 +000080}
81
82void
83test2()
84{
85 typedef std::mt19937_64 E;
86 static_assert((E::word_size == 64), "");
87 static_assert((E::state_size == 312), "");
88 static_assert((E::shift_size == 156), "");
89 static_assert((E::mask_bits == 31), "");
90 static_assert((E::xor_mask == 0xb5026f5aa96619e9ull), "");
91 static_assert((E::tempering_u == 29), "");
92 static_assert((E::tempering_d == 0x5555555555555555ull), "");
93 static_assert((E::tempering_s == 17), "");
94 static_assert((E::tempering_b == 0x71d67fffeda60000ull), "");
95 static_assert((E::tempering_t == 37), "");
96 static_assert((E::tempering_c == 0xfff7eee000000000ull), "");
97 static_assert((E::tempering_l == 43), "");
98 static_assert((E::initialization_multiplier == 6364136223846793005ull), "");
99 /*static_*/assert((E::min() == 0)/*, ""*/);
100 /*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/);
101 static_assert((E::default_seed == 5489u), "");
Howard Hinnant16694b52012-12-12 21:14:28 +0000102 where(E::word_size);
103 where(E::state_size);
104 where(E::shift_size);
105 where(E::mask_bits);
106 where(E::xor_mask);
107 where(E::tempering_u);
108 where(E::tempering_d);
109 where(E::tempering_s);
110 where(E::tempering_b);
111 where(E::tempering_t);
112 where(E::tempering_c);
113 where(E::tempering_l);
114 where(E::initialization_multiplier);
115 where(E::default_seed);
Howard Hinnant3e519522010-05-11 19:42:16 +0000116}
117
118int main()
119{
120 test1();
121 test2();
122}