|
Aegis2D
Modular C++26 2D game engine for networked games
|
Seeded pseudo-random generator (PCG32), for gameplay the server must replay. More...
#include <aegis2d/core/random.hpp>
Public Types | |
| using | result_type = std::uint32_t |
| Type of the raw numbers. | |
Public Member Functions | |
| constexpr | Random (std::uint64_t seed, std::uint64_t stream=0) noexcept |
| Starts a sequence. | |
| constexpr result_type | next () noexcept |
| Next raw number. | |
| constexpr result_type | operator() () noexcept |
| Next raw number. | |
| constexpr std::uint32_t | below (std::uint32_t bound) noexcept |
| Whole number below a bound, every value equally likely. | |
| constexpr float | uniform () noexcept |
| Real number between 0 and 1. | |
| constexpr float | uniform (float low, float high) noexcept |
| Real number between two bounds. | |
Static Public Member Functions | |
| static constexpr result_type | min () noexcept |
| Smallest raw number. | |
| static constexpr result_type | max () noexcept |
| Largest raw number. | |
Seeded pseudo-random generator (PCG32), for gameplay the server must replay.
A given seed and stream always give the same numbers, on every compiler and standard library: unlike std::uniform_int_distribution and std::uniform_real_distribution, whose results differ between libstdc++, libc++ and MSVC, below() and uniform() are defined here. 16 bytes of state, fast, good statistical quality, but not for cryptography. It meets std::uniform_random_bit_generator, so it also works with std::shuffle, whose results then depend on the standard library.
| using aegis2d::core::Random::result_type = std::uint32_t |
Type of the raw numbers.
|
inlineexplicitconstexprnoexcept |
Starts a sequence.
| seed | Picks the starting point: the same seed gives the same numbers. |
| stream | Picks one of 2^63 independent sequences, e.g. one per system, so that drawing more numbers in one does not change the others. |
|
inlineconstexprnoexcept |
Whole number below a bound, every value equally likely.
| bound | Number of possible values. |
[0, bound), or 0 when bound is 0.
|
inlinestaticconstexprnoexcept |
Largest raw number.
|
inlinestaticconstexprnoexcept |
Smallest raw number.
|
inlineconstexprnoexcept |
Next raw number.
|
inlineconstexprnoexcept |
Next raw number.
|
inlineconstexprnoexcept |
Real number between 0 and 1.
[0, 1), with the 24 bits of precision a float has.
|
inlineconstexprnoexcept |
Real number between two bounds.
| low | One bound. |
| high | The other bound. |
low + (high - low) * uniform(): from low to high, every value equally likely.