#pragma once #include namespace roro::games { // The Games' own dice (issue #101): the same seed gives the same game, which is what lets their // rules be tested. xorshift32; never 0. class Rng { public: explicit Rng(uint32_t seed) : s_(seed ? seed : 0x9E3779B9u) {} uint32_t next() { s_ ^= s_ << 13; s_ ^= s_ >> 17; s_ ^= s_ << 5; return s_; } int below(int n) { return n <= 1 ? 0 : static_cast(next() % static_cast(n)); } float unit() { return (next() >> 8) / 16777216.0f; } // 0 up to 1 private: uint32_t s_; }; } // namespace roro::games