1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <random>
10
11 // template <class UIntType, size_t w, size_t n, size_t m, size_t r,
12 // UIntType a, size_t u, UIntType d, size_t s,
13 // UIntType b, size_t t,
14 // UIntType c, size_t l, UIntType f>
15 // class mersenne_twister_engine;
16
17 // template <class Sseq> explicit mersenne_twister_engine(Sseq &q);
18 //
19 // [ ... ] Finally, if the most significant $w-r$ bits of $X_{-n}$ are zero,
20 // and if each of the other resulting $X_i$ is $0$, changes $X_{-n}$ to
21 // $ 2^{w-1} $.
22
23 #include <random>
24
25 #include <algorithm>
26 #include <cassert>
27 #include <cstddef>
28
29 #include "test_macros.h"
30
31 struct all_zero_seed_seq {
32 typedef unsigned int result_type;
33
all_zero_seed_seqall_zero_seed_seq34 all_zero_seed_seq() {}
35
36 template <typename InputIterator>
all_zero_seed_seqall_zero_seed_seq37 all_zero_seed_seq(InputIterator, InputIterator) {}
38 #if TEST_STD_VER >= 11
all_zero_seed_seqall_zero_seed_seq39 all_zero_seed_seq(std::initializer_list<result_type>) {}
40 #endif
41
42 template <typename RandomAccessIterator>
generateall_zero_seed_seq43 void generate(RandomAccessIterator rb, RandomAccessIterator re) {
44 std::fill(rb, re, 0u);
45 }
46
sizeall_zero_seed_seq47 std::size_t size() const { return 0u; }
paramall_zero_seed_seq48 template <typename OutputIterator> void param(OutputIterator) const {}
49 };
50
51 template <typename result_type, std::size_t word_size>
test(void)52 void test(void) {
53 const std::size_t state_size = 1u;
54 const std::size_t shift_size = 1u;
55 const std::size_t tempering_l = word_size;
56
57 all_zero_seed_seq q;
58 std::mersenne_twister_engine<result_type, word_size, state_size,
59 shift_size,
60 0u,
61 0x0,
62 0u, 0x0, 0u, 0x0, 0u, 0x0,
63 tempering_l,
64 0u>
65 e(q);
66
67 const result_type Xneg1 = result_type(1) << (word_size - 1);
68 const result_type Y = Xneg1;
69 const result_type X0 = Xneg1 ^ (Y >> 1);
70 assert(e() == X0);
71 }
72
main(int,char **)73 int main(int, char**) {
74 // Test for k == 1: word_size <= 32.
75 test<unsigned short, 3u>();
76
77 // Test for k == 2: (32 < word_size <= 64).
78 test<unsigned long long, 33u>();
79
80 return 0;
81 }
82