#pragma once #include namespace evo { // SplitMix64; explicit unsigned wraparound. Reference and scope: ADR-0007. // This algorithm is never a security primitive. class Random { public: explicit constexpr Random(std::uint64_t state) noexcept : state_{state} {} [[nodiscard]] constexpr std::uint64_t next() noexcept { state_ += 0x9e3779b97f4a7c15ULL; auto value = state_; value = (value ^ (value >> 30U)) * 0xbf58476d1ce4e5b9ULL; value = (value ^ (value >> 27U)) * 0x94d049bb133111ebULL; return value ^ (value >> 31U); } // The 2^64-1 accepted outputs divide equally among three bins. [[nodiscard]] constexpr std::uint32_t ternary() noexcept { auto value = next(); while (value == 0) { value = next(); } return static_cast(value % 3U); } [[nodiscard]] constexpr std::uint64_t state() const noexcept { return state_; } private: std::uint64_t state_; }; } // namespace evo