-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.cc
139 lines (113 loc) · 2.78 KB
/
test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <algorithm>
#include <iomanip>
#include <vector>
#if __cplusplus >= 202002L // C++20 (and later) code
# include <random>
#endif
#include "xoshiro256ss.h"
bool check_xoshiro256ss()
{
vigna::xoshiro256ss gen;
const std::vector<vigna::xoshiro256ss::result_type> reference =
{
11520u,
0u,
1509978240u,
1215971899390074240u,
1216172134540287360u,
607988272756665600u,
16172922978634559625u,
8476171486693032832u,
10595114339597558777u,
2904607092377533576u
};
// Check first numbers of the sequence for a given state.
gen.seed({1, 2, 3, 4});
for (auto r : reference)
{
const auto v(gen());
if (v != r)
{
std::cerr << "Error: " << v << " != " << r << '\n';
return false;
}
}
// Check `discard` method.
gen.seed({1, 2, 3, 4});
const unsigned long long SKIPPED(5);
gen.discard(SKIPPED);
for (auto r(std::next(reference.begin(), SKIPPED));
r != reference.end();
++r)
{
const auto v(gen());
if (v != *r)
{
std::cerr << "Error: " << v << " != " << *r << '\n';
return false;
}
}
#if __cplusplus >= 202002L
// Check `std::uniform_random_bit_generator` concept
static_assert(std::uniform_random_bit_generator<decltype(gen)>);
#endif
std::cout << std::setw(16) << std::left << "xoshiro256**" << "[OK]\n";
return true;
}
bool check_xoroshiro128p()
{
vigna::xoroshiro128p gen;
const std::vector<vigna::xoroshiro128p::result_type> reference =
{
3791206066794290419u,
15895565023667069775u,
10353094603425901311u,
2310587765582178245u,
6248954372557818163u,
17214788232953710521u,
15724695866974583607u,
6742597202947952447u,
1275020938797310118u,
8226711840634510758u
};
// Check first numbers of the sequence for a given state.
gen.seed();
for (auto r : reference)
{
const auto v(gen());
if (v != r)
{
std::cerr << "Error: " << v << " != " << r << '\n';
return false;
}
}
// Check `discard` method.
gen.seed();
const unsigned long long SKIPPED(5);
gen.discard(SKIPPED);
for (auto r(std::next(reference.begin(), SKIPPED));
r != reference.end();
++r)
{
const auto v(gen());
if (v != *r)
{
std::cerr << "Error: " << v << " != " << *r << '\n';
return false;
}
}
#if __cplusplus >= 202002L
// Check `std::uniform_random_bit_generator` concept
static_assert(std::uniform_random_bit_generator<decltype(gen)>);
#endif
std::cout << std::setw(16) << std::left << "xoroshiro128+" << "[OK]\n";
return true;
}
int main()
{
const std::vector<bool> results =
{check_xoshiro256ss(), check_xoroshiro128p()};
return std::all_of(results.begin(), results.end(),
[](bool v) { return v == true; })
? 0 : 1;
}