25 constexpr explicit Random(std::uint64_t seed, std::uint64_t stream = 0) noexcept
26 : increment_{(stream << 1U) | 1U} {
39 return std::numeric_limits<result_type>::max();
45 const std::uint64_t old = state_;
46 state_ = (old * multiplier) + increment_;
47 const auto shifted =
static_cast<std::uint32_t
>(((old >> 18U) ^ old) >> 27U);
48 const auto rotation =
static_cast<std::uint32_t
>(old >> 59U);
49 return (shifted >> rotation) | (shifted << ((32U - rotation) & 31U));
58 constexpr std::uint32_t
below(std::uint32_t bound)
noexcept {
64 const std::uint32_t threshold = (0U - bound) % bound;
66 const std::uint64_t product = std::uint64_t{
next()} * bound;
67 if (
static_cast<std::uint32_t
>(product) >= threshold) {
68 return static_cast<std::uint32_t
>(product >> 32U);
76 return static_cast<float>(
next() >> 8U) * (1.0F /
static_cast<float>(1U << 24U));
84 constexpr float uniform(
float low,
float high)
noexcept {
85 return low + ((high - low) *
uniform());
89 static constexpr std::uint64_t multiplier = 6364136223846793005U;
91 std::uint64_t state_ = 0;
92 std::uint64_t increment_;
Seeded pseudo-random generator (PCG32), for gameplay the server must replay.
Definition random.hpp:16
constexpr std::uint32_t below(std::uint32_t bound) noexcept
Whole number below a bound, every value equally likely.
Definition random.hpp:58
constexpr Random(std::uint64_t seed, std::uint64_t stream=0) noexcept
Starts a sequence.
Definition random.hpp:25
static constexpr result_type max() noexcept
Largest raw number.
Definition random.hpp:38
constexpr float uniform(float low, float high) noexcept
Real number between two bounds.
Definition random.hpp:84
static constexpr result_type min() noexcept
Smallest raw number.
Definition random.hpp:34
constexpr float uniform() noexcept
Real number between 0 and 1.
Definition random.hpp:75
constexpr result_type operator()() noexcept
Next raw number.
Definition random.hpp:53
constexpr result_type next() noexcept
Next raw number.
Definition random.hpp:44
std::uint32_t result_type
Type of the raw numbers.
Definition random.hpp:19
Logging, time, main loop, events and configuration shared by client and server.
Definition clock.hpp:11