8#include "ncengine/type/EngineId.h"
31 :
Random(std::random_device{}())
39 explicit Random(uint64_t seed) noexcept
43 m_distribution{0.0f, std::nextafter(1.0f, std::numeric_limits<float>::max())}
57 void Seed(uint64_t seed)
noexcept { *
this =
Random{seed}; }
63 auto Seed() const noexcept {
return m_seed; }
75 auto Get() noexcept ->
float {
return m_distribution(m_generator); }
81 auto GetU64() noexcept -> uint64_t {
return m_generator(); }
107 auto Between(
float min,
float max)
noexcept ->
float {
return Get() * (max - min) + min; }
115 auto Between(uint64_t min, uint64_t max)
noexcept -> uint64_t
117 auto distribution = std::uniform_int_distribution<uint64_t>{min, max};
118 return distribution(m_generator);
160 std::uniform_real_distribution<float> m_distribution;
Modules are extensions that provide functionality to the engine.
Definition: Module.h:19
Random number generator.
Definition: Random.h:25
Random() noexcept
Default construct a new Random object.
Definition: Random.h:30
friend bool operator!=(const Random &lhs, const Random &rhs) noexcept
Check if two generators have different states.
Definition: Random.h:155
auto GetU64() noexcept -> uint64_t
Generate a random uint64_t in the range [0, std::numeric_limits<uint64_t>::max()].
Definition: Random.h:81
auto GetVector3() noexcept -> Vector3
Generate a random Vector3 with components in the range [0, 1].
Definition: Random.h:93
auto Fork() noexcept
Returns a new Random instance seeded with the next generator value.
Definition: Random.h:51
auto Get() noexcept -> float
Generate a random float in the range [0, 1].
Definition: Random.h:75
auto Between(uint64_t min, uint64_t max) noexcept -> uint64_t
Generate a random uint64_t in the range [min, max].
Definition: Random.h:115
auto Seed() const noexcept
Get the current seed.
Definition: Random.h:63
auto GetGenerator() -> Xoshiro256ss &
Get the underlying generator.
Definition: Random.h:69
friend bool operator==(const Random &lhs, const Random &rhs) noexcept
Check if two generators have the same state.
Definition: Random.h:149
auto Between(const Vector3 &min, const Vector3 &max) noexcept -> Vector3
Generate a random Vector3 with components in the range [min, max].
Definition: Random.h:135
auto GetVector4() noexcept -> Vector4
Generate a random Vector4 with components in the range [0, 1].
Definition: Random.h:99
auto Between(const Vector2 &min, const Vector2 &max) noexcept -> Vector2
Generate a random Vector2 with components in the range [min, max].
Definition: Random.h:127
auto Between(const Vector4 &min, const Vector4 &max) noexcept -> Vector4
Generate a random Vector4 with components in the range [min, max].
Definition: Random.h:143
void Seed(uint64_t seed) noexcept
Seed the generator.
Definition: Random.h:57
auto GetVector2() noexcept -> Vector2
Generate a random Vector2 with components in the range [0, 1].
Definition: Random.h:87
auto Between(float min, float max) noexcept -> float
Generate a random float in the range [min, max].
Definition: Random.h:107
Random(uint64_t seed) noexcept
Construct a new Random object from a seed.
Definition: Random.h:39
Random number engine based on Xoshiro256** by David Blackman and Sebastiano Vigna.
Definition: Xoshiro256.h:11
A two component vector.
Definition: Vector.h:13
A three component vector.
Definition: Vector.h:29
A four component vector.
Definition: Vector.h:48