4#include "fastmm/core/config_macros.hpp"
12 explicit constexpr Xoshiro256ss(std::uint64_t seed = 0x9E3779B97F4A7C15ULL) noexcept {
16 constexpr void reseed(std::uint64_t seed)
noexcept {
18 std::uint64_t x = seed;
20 x += 0x9E3779B97F4A7C15ULL;
22 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ULL;
23 z = (z ^ (z >> 27)) * 0x94D049BB133111EBULL;
28 constexpr std::uint64_t
next() noexcept {
29 const std::uint64_t result = rotl(s_[1] * 5, 7) * 9;
30 const std::uint64_t t = s_[1] << 17;
36 s_[3] = rotl(s_[3], 45);
42 constexpr std::uint64_t
uniform(std::uint64_t n)
noexcept {
45 const std::uint64_t x =
next();
46 const Uint128 m =
static_cast<Uint128
>(x) * n;
47 const auto l =
static_cast<std::uint64_t
>(m);
48 if (l >= (0 - n) % n)
return static_cast<std::uint64_t
>(m >> 64);
52 constexpr std::int64_t
between(std::int64_t lo, std::int64_t hi)
noexcept {
53 return lo +
static_cast<std::int64_t
>(
uniform(
static_cast<std::uint64_t
>(hi - lo) + 1));
56 double uniform01() noexcept {
return static_cast<double>(
next() >> 11) * 0x1.0p-53; }
64 static constexpr std::uint64_t rotl(std::uint64_t x,
int k)
noexcept {
65 return (x << k) | (x >> (64 - k));
67 std::uint64_t s_[4] = {};
constexpr std::uint64_t operator()() noexcept
Definition rng.hpp:41
constexpr std::int64_t between(std::int64_t lo, std::int64_t hi) noexcept
Integer in [lo, hi] inclusive.
Definition rng.hpp:54
constexpr std::uint64_t uniform(std::uint64_t n) noexcept
Unbiased integer in [0, n) (Lemire's multiply-shift with rejection).
Definition rng.hpp:44
std::uint64_t result_type
std::uniform_random_bit_generator interface
Definition rng.hpp:61
double uniform01() noexcept
Double in [0, 1). Sim/backtest only (hot path is integer).
Definition rng.hpp:58
constexpr std::uint64_t next() noexcept
Definition rng.hpp:30
constexpr void reseed(std::uint64_t seed) noexcept
Definition rng.hpp:18
static constexpr result_type min() noexcept
Definition rng.hpp:62
static constexpr result_type max() noexcept
Definition rng.hpp:63
Definition strategy.hpp:16