![]() |
Ultra 0.9.4
|
#include "kernel/interval.h"#include "utility/assert.h"#include "utility/misc.h"#include "utility/xoshiro256ss.h"#include <random>#include <type_traits>Go to the source code of this file.
Namespaces | |
| namespace | ultra |
Typedefs | |
| using | ultra::random::engine_t = vigna::xoshiro256ss |
Enumerations | |
| enum class | distribution { uniform , normal } |
Functions | |
| engine_t & | ultra::random::engine () |
| std::size_t | ultra::random::ring (std::size_t base, std::size_t radius, std::size_t n) |
| void | ultra::random::randomize () |
| template<std::floating_point T> | |
| T | ultra::random::between (T min, T sup) |
| template<std::integral T> | |
| T | ultra::random::between (T min, T sup) |
|
template<class T> requires std::is_enum_v<T> | |
| T | ultra::random::between (T min, T sup) |
| template<class T> requires std::is_arithmetic_v<T> || std::is_enum_v<T> | |
| T | ultra::random::sup (T sup) |
| template<std::ranges::sized_range C> | |
| std::ranges::range_reference_t< const C > | ultra::random::element (const C &c) |
| template<ArithmeticScalar A> | |
| A | ultra::random::element (const interval< A > &i) |
| template<std::ranges::sized_range C> | |
| C::value_type & | ultra::random::element (C &c) |
| bool | ultra::random::boolean (double p) |
| bool | ultra::random::boolean () |
| template<class T> requires std::is_arithmetic_v<T> | |
| T | ultra::random::ephemeral (distribution d, T p1, T p2) |
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/
| using ultra::random::engine_t = vigna::xoshiro256ss |
xoshiro256** (XOR/shift/rotate) is an all-purpose, rock-solid generator (not a cryptographically secure generator). It has excellent (sub-ns) speed, a state space (256 bits) that is large enough for any parallel application, and it passes all tests we are aware of.
|
nodiscard |
Picks up a random integer value uniformly distributed in the set of integers {min, min+1, ..., sup-1}.
| [in] | min | minimum random number |
| [in] | sup | upper bound |
|
nodiscard |
A specialization for floating point values of the random::between(T, T) template function.
| [in] | min | minimum random number |
| [in] | sup | upper bound |
|
inlinenodiscard |
|
inlinenodiscard |
| [in] | p | a probability ([0;1] range) |
|
nodiscard |
| [in] | c | a STL container |
|
nodiscard |
| [in] | c | a STL container |
|
nodiscard |
| [in] | i | a right-open interval |
|
nodiscard |
Every thread has its own generator initialised with a different seed.
|
nodiscard |
Used for ephemeral random constant generation.
| [in] | d | type of distribution |
| [in] | p1 | minimum for uniform distribution; mean - stddev/2 for normal distribution |
| [in] | p2 | maximum for uniform distribution, mean + stddev/2 for normal distribution |
| void ultra::random::randomize | ( | ) |
Switches the random subsystem to an unpredictable state.
This function "re-bases" the process-wide seed counter so that random engines created after this call are typically seeded unpredictably.
Implementation notes / assumptions:
Each thread owns its own thread-local random engine; therefore, only engines created after this call are affected. Existing engines are left unchanged.
This design allows deterministic and non-deterministic random behaviour to coexist within the same program, depending on when engines are initialised.
|
nodiscard |
Returns a random number in a modular arithmetic system.
| [in] | base | a base number |
| [in] | radius | maximum distance from the base number |
| [in] | n | modulus |
|
nodiscard |
| [in] | sup | upper bound |