blob: 465a83c9aa86b34157a015f1284a21679ce6f6d1 (
plain) (
blame)
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
|
//===-- xoshiro.h ---------------------------------------------------------===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstdint>
/// A xoshiro512** generator
class xoshiro512 {
static constexpr const ::std::uint64_t A = 11;
static constexpr const ::std::uint64_t B = 21;
static constexpr const ::std::uint64_t S = 5;
static constexpr const ::std::uint64_t R = 7;
static constexpr const ::std::uint64_t T = 9;
::std::uint64_t s[8] = {0x243F6A8885A308D3u, 0x13198A2E03707344u,
0xA4093822299F31D0u, 0x082EFA98EC4E6C89u,
0x452821E638D01377u, 0xBE5466CF34E90C6Cu,
0xC0AC29B7C97C50DDu, 0x3F84D5B5B5470917u};
public:
explicit xoshiro512(std::uint64_t const seed) noexcept {
for (auto &x : s) {
x ^= seed;
}
}
using result_type = std::uint64_t;
std::uint64_t operator()() noexcept {
auto const t = s[1] * S;
auto const result = ((t << R) | (t >> (64 - R))) * T;
auto const u = s[1] << A;
s[2] ^= s[0];
s[5] ^= s[1];
s[1] ^= s[2];
s[7] ^= s[3];
s[3] ^= s[4];
s[4] ^= s[5];
s[0] ^= s[6];
s[6] ^= s[7];
s[6] ^= u;
s[7] = ((s[7] << B) | (s[7] >> (64 - B)));
return result;
}
static constexpr ::std::uint64_t(min)() noexcept { return 0; }
static constexpr ::std::uint64_t(max)() noexcept {
return static_cast<std::uint64_t>(0) - static_cast<std::uint64_t>(1);
}
};
|