random.h¶
| File Path | engine/include/conjure/core/random.h |
| API ↗ | Time, events and random |
Pseudo-random numbers.
Classes¶
| File | Description |
|---|---|
random::random_engine |
An owned, independently seeded engine with the helpers above as members. Satisfies std::uniform_random_bit_generator so it can also feed the standard algorithms. |
Type Aliases¶
random::engine¶
The engine type used throughout Conjure. Its output sequence is fixed by the C++ standard, so seeded sequences are portable.
random::random_engine::result_type¶
Constants¶
| Name | Type | Value | Description |
|---|---|---|---|
random::DEFAULT_SEED |
inline constexpr u64 |
0x5EED |
Seed used by every thread's default engine until seed() changes it. |
Functions¶
Public¶
random::chance¶
random::chance¶template <std::uniform_random_bit_generator Generator> [[nodiscard]] bool chance(Generator &generator, f64 probability);True with the given probability (clamped to [0, 1]). 0 is never true, 1 is always true.
random::current_seed¶
random::current_seed¶[[nodiscard]] CONJURE_API u64 current_seed() noexcept;The seed new default engines are created with.
random::default_engine¶
random::default_engine¶[[nodiscard]] CONJURE_API engine &default_engine() noexcept;This thread's engine. Created on first use, seeded with the process seed (see seed()). Every thread starts from the same seed, so two threads doing the same work produce the same numbers.
random::detail::bounded_u64¶
random::detail::bounded_u64¶template <std::uniform_random_bit_generator Generator> [[nodiscard]] u64 bounded_u64(Generator &generator, u64 span);Uniform integer in [0, span] (inclusive). The span of all 64 bits is a plain draw.
random::detail::next_u64¶
random::detail::next_u64¶template <std::uniform_random_bit_generator Generator> [[nodiscard]] u64 next_u64(Generator &generator);Draws exactly 64 uniformly distributed bits from any generator, combining several outputs when the generator yields fewer bits per call.
random::detail::unit_f32¶
random::detail::unit_f32¶template <std::uniform_random_bit_generator Generator> [[nodiscard]] f32 unit_f32(Generator &generator);Uniform float in [0, 1) with 24 random bits.
random::detail::unit_f64¶
random::detail::unit_f64¶template <std::uniform_random_bit_generator Generator> [[nodiscard]] f64 unit_f64(Generator &generator);Uniform double in [0, 1) with 53 random bits.
random::seed¶
random::seed¶CONJURE_API void seed(u64 value) noexcept;Sets the seed that every thread's default engine receives on first use and reseeds the calling thread's engine immediately, so the sequence restarts on this thread. Engines already created on other threads keep running until they call seed() themselves. Thread-safe.
random::uniform¶
random::uniform¶template <std::uniform_random_bit_generator Generator, std::integral T> requires (!std::same_as<T, bool>) [[nodiscard]] T uniform(Generator &generator, T min, T max);Uniform integer in the inclusive range [min, max]. Asserts when min > max and then returns min. Works for every integral type including 8-bit ones (bool excluded).
template <std::uniform_random_bit_generator Generator, std::floating_point T> [[nodiscard]] T uniform(Generator &generator, T min, T max);Uniform floating point value in the half-open range [min, max). Asserts when min > max and then returns min. Never returns max.
random::unit_vector3¶
random::unit_vector3¶template <typename Vector3 = std::array<f32, 3>, std::uniform_random_bit_generator Generator> [[nodiscard]] Vector3 unit_vector3(Generator &generator);A uniformly distributed point on the unit sphere, built as Vector3{x, y, z}. The default is a plain array; pass math::vec3 (or any type constructible from three floats) to get it. Consumes two 64-bit draws (two calls of random::engine). x and y come from std::cos / std::sin and are not bit-identical across platforms; do not hash or compare them bit for bit across machines.