-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathexample.cpp
86 lines (76 loc) · 1.88 KB
/
example.cpp
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
# include <iostream>
# include <random>
# include "XoshiroCpp.hpp"
int main()
{
using namespace XoshiroCpp;
std::cout << "# Initialize with a default 64-bit seed\n";
{
Xoshiro256PlusPlus rng;
std::cout << rng() << '\n'
<< rng() << '\n'
<< rng() << '\n';
}
std::cout << "\n# Initialize with a 64-bit seed\n";
{
constexpr std::uint64_t seed = 777;
Xoshiro256PlusPlus rng(seed);
std::cout << rng() << '\n'
<< rng() << '\n'
<< rng() << '\n';
}
std::cout << "\n# Initialize with a given state\n";
{
// poorly distributed
constexpr std::uint64_t seed0 = 0;
constexpr std::uint64_t seed1 = 0;
constexpr std::uint64_t seed2 = 1;
constexpr std::uint64_t seed3 = 1;
constexpr Xoshiro256PlusPlus::state_type state =
{
seed0,
seed1,
seed2,
seed3
};
Xoshiro256PlusPlus rng(state);
std::cout << rng() << '\n'
<< rng() << '\n'
<< rng() << '\n';
}
std::cout << "\n# Initialize with a given state (SplitMix64 is used for entropy)\n";
{
// poorly distributed
constexpr std::uint64_t seed0 = 0;
constexpr std::uint64_t seed1 = 0;
constexpr std::uint64_t seed2 = 1;
constexpr std::uint64_t seed3 = 1;
constexpr Xoshiro256PlusPlus::state_type state =
{
SplitMix64(seed0)(),
SplitMix64(seed1)(),
SplitMix64(seed2)(),
SplitMix64(seed3)()
};
Xoshiro256PlusPlus rng(state);
std::cout << rng() << '\n'
<< rng() << '\n'
<< rng() << '\n';
}
std::cout << "\n# Generate double in the range of [0.0, 1.0)\n";
{
Xoshiro256PlusPlus rng(111);
std::cout << DoubleFromBits(rng()) << '\n'
<< DoubleFromBits(rng()) << '\n'
<< DoubleFromBits(rng()) << '\n';
}
std::cout << "\n# Generate int in the range of [1, 6]\n";
{
Xoshiro256PlusPlus rng(222);
std::uniform_int_distribution<int> dist(1, 6);
std::cout << dist(rng) << '\n'
<< dist(rng) << '\n'
<< dist(rng) << '\n';
}
}