RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
Loading...
Searching...
No Matches
splitmix64.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace randlib
6{
7
14{
15public:
16 using result_type = std::uint64_t;
17
18 constexpr explicit SplitMix64(std::uint64_t seed = 0) noexcept : state(seed) {}
19
20 static constexpr result_type min() noexcept { return 0; }
21 static constexpr result_type max() noexcept { return ~result_type{0}; }
22
23 constexpr void seed(std::uint64_t value) noexcept { state = value; }
24
25 constexpr result_type operator()() noexcept
26 {
27 std::uint64_t z = (state += 0x9E3779B97F4A7C15ULL);
28 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ULL;
29 z = (z ^ (z >> 27)) * 0x94D049BB133111EBULL;
30 return z ^ (z >> 31);
31 }
32
33 constexpr void discard(unsigned long long n) noexcept { state += n * 0x9E3779B97F4A7C15ULL; }
34
35 friend constexpr bool operator==(const SplitMix64 &, const SplitMix64 &) = default;
36
37private:
38 std::uint64_t state;
39};
40
41} // namespace randlib
The SplitMix64 class Sebastiano Vigna's SplitMix64 generator.
Definition splitmix64.hpp:14
constexpr void seed(std::uint64_t value) noexcept
Definition splitmix64.hpp:23
std::uint64_t result_type
Definition splitmix64.hpp:16
static constexpr result_type min() noexcept
Definition splitmix64.hpp:20
constexpr result_type operator()() noexcept
Definition splitmix64.hpp:25
friend constexpr bool operator==(const SplitMix64 &, const SplitMix64 &)=default
static constexpr result_type max() noexcept
Definition splitmix64.hpp:21
constexpr void discard(unsigned long long n) noexcept
Definition splitmix64.hpp:33
constexpr SplitMix64(std::uint64_t seed=0) noexcept
Definition splitmix64.hpp:18
Definition bivariate_normal.hpp:10