Template Class BasicRandomStatic#
Defined in File Random.h
Class Documentation#
-
template<typename engine, typename Seeder = SeederDefault, template<typename> class IntegerDist = std::uniform_int_distribution, template<typename> class RealDist = std::uniform_real_distribution, typename BoolDist = std::bernoulli_distribution>
class BasicRandomStatic# Base template class for random with static API and static internal member storage.
- Thread safety
This is NOT thread safe but more efficient than BasicRandomThreadLocal.
- Template Parameters:
engine – A random engine with interface like in the std::mt19937.
Seeder – A seeder type which return seed for internal engine through operator().
Public Types
-
template<typename T>
using IntegerDistT = IntegerDist<T># Type of used integer distribution.
- Template Parameters:
T – Integer type.
Public Functions
-
constexpr BasicRandomStatic() = delete#
Constructor.
-
constexpr ~BasicRandomStatic() = delete#
Destructor.
-
consteval BasicRandomStatic(const BasicRandomStatic&) = delete#
Copy constructor.
-
consteval BasicRandomStatic operator=(const BasicRandomStatic&) = delete#
Copy assignment operator.
-
consteval BasicRandomStatic(BasicRandomStatic&&) noexcept = delete#
Move constructor.
-
consteval BasicRandomStatic operator=(BasicRandomStatic&&) noexcept = delete#
Move assignment operator.
Public Static Functions
-
static inline constexpr engine::result_type Min()#
Retrieve the minimum value potentially generated by the random-number engine.
- Returns:
Minimum value.
-
static inline constexpr engine::result_type Max()#
Retrieve the maximum value potentially generated by the random-number engine.
- Returns:
Maximum value.
-
static inline void Discard(const u64 z)#
Advances the internal state by z times.
- Parameters:
z – How many times to advance.
-
static inline void Reseed()#
Reseed by seeder.
-
static inline void Seed(const typename engine::result_type value = engine::default_seed)#
Re-Initializes the internal state of the random-number engine using new seed value.
- Parameters:
value – Seed value to use in the initialization of the internal state.
-
template<typename SSeq>
static inline void Seed(SSeq &seq)# Re-Initializes the internal state of the random-number engine using new seed value.
- Template Parameters:
SSeq – Seed sequence.
- Parameters:
seq – Seed sequence to use in the initialization of the internal state
-
static inline engine::result_type Get()#
Get a random number from engine in [Min(), Max()] range.
- Returns:
Random number.
-
static inline bool IsEqual(const engine &other)#
Compares internal pseudo-random number engine with ‘other’ pseudo-random number engine. Two engines are equal, if their internal states are equivalent, that is, if they would generate equivalent values for any number of calls of operator().
- Parameters:
other – Engine, with which the internal engine will be compared.
- Returns:
True, if other and internal engine are equal.
-
template<typename CharT, typename Traits>
static inline void Serialize(std::basic_ostream<CharT, Traits> &ost)# Serializes the internal state of the internal pseudo-random number engine as a sequence of decimal numbers separated by one or more spaces, and inserts it to the stream ost. The fill character and the formatting flags of the stream are ignored and unaffected.
- Parameters:
ost – Output stream to insert the data to.
-
template<typename CharT, typename Traits>
static inline void Deserialize(std::basic_istream<CharT, Traits> &ist)# Restores the internal state of the internal pseudo-random number engine from the serialized representation, which was created by an earlier call to ‘Serialize’ using a stream with the same imbued locale and the same CharT and Traits. If the input cannot be deserialized, internal engine is left unchanged and fail-Bit is raised on ist.
- Parameters:
ist – Input stream to extract the data from.
-
template<typename T>
static inline T Get(T from = std::numeric_limits<T>::min(), T to = std::numeric_limits<T>::max())# Generate a random integer number in a [from; to] range by std::uniform_int_distribution.
- Parameters:
from – First limit number of a random range.
to – Second limit number of a random range.
- Returns:
A random integer number in a [from; to] range.
-
template<typename T>
static inline T Get(T from = std::numeric_limits<T>::min(), T to = std::numeric_limits<T>::max()) Generate a random real number in a [from; to] range by std::uniform_real_distribution.
- Parameters:
from – First limit number of a random range.
to – Second limit number of a random range.
- Returns:
A random real number in a [from; to] range.
-
template<typename T>
static inline T Get(T from = std::numeric_limits<T>::min(), T to = std::numeric_limits<T>::max()) Generate a random byte number in a [from; to] range.
- Parameters:
from – First limit number of a random range.
to – Second limit number of a random range.
- Returns:
A random byte number in a [from; to] range.
-
template<typename Key, typename A, typename B, typename C = typename std::common_type<A, B>::type>
static inline C Get(A from = std::numeric_limits<A>::min(), B to = std::numeric_limits<B>::max())# Generate a random common_type number in a [from; to] range.
- Template Parameters:
Key – Key type for this version of ‘Get’ method Type should be ‘(THIS_TYPE)::Common’ struct.
- Parameters:
from – First limit number of a random range.
to – Second limit number of a random range.
- Returns:
A random common_type number in a [from; to] range.
-
template<typename T>
static inline T Get(T from = std::numeric_limits<T>::min(), T to = std::numeric_limits<T>::max()) Generate a random character in a [from; to] range by std::uniform_int_distribution.
- Parameters:
from – First limit number of a random range.
to – Second limit number of a random range.
- Returns:
A random character in a [from; to] range.
-
template<typename T>
static inline bool Get(const f64 probability = 0.5)# Generate a bool value with specific probability by std::bernoulli_distribution.
- Parameters:
probability – Probability of generating true in [0; 1] range 0 means always false, 1 means always true.
- Returns:
‘true’ with ‘probability’ probability (‘false’ otherwise).
-
template<typename T>
static inline T Get(std::initializer_list<T> init_list)# Get random value from initializer_list. Should be 1 or more elements in initializer_list.
Note
Elements in initializer_list can’t be moved!
- Parameters:
init_list – Initializer_list with values.
- Returns:
Random value from initializer_list.
- template<typename InputIt> static inline ::value InputIt Get (InputIt first, InputIt last)
Get random iterator from iterator range.
- Parameters:
first – Range of elements.
last – Range of elements.
- Returns:
Random iterator from [first, last) range.
-
template<typename Container>
static inline decltype(Container::iterator) Get(Container &container)# Get random iterator from container.
- Parameters:
container – Container with elements.
- Returns:
Random iterator from container.
-
template<typename T, usize N>
static inline T *Get(T (&array)[N])# Get random pointer from built-in array.
- Parameters:
array – Built-in array with elements.
- Returns:
Pointer to random element in array.
-
template<typename Dist, typename ...Args>
static inline Dist::result_type Get(Args&&... args)# Get value from custom dist distribution seeded by internal random engine.
- Template Parameters:
Dist – Type of custom distribution with next concept.
Args – Arguments which will be forwarded to dist constructor.
- Returns:
Value from custom distribution.
-
template<typename Dist>
static inline Dist::result_type Get(Dist &dist)# Get value from custom ‘dist’ distribution seeded by internal random engine.
- Parameters:
dist – Custom distribution with next concept
- Returns:
Value from custom ‘dist’ distribution
-
template<typename RandomIt>
static inline void Shuffle(RandomIt first, RandomIt last)# Reorders the elements in the given range [first, last) such that each possible permutation of those elements has equal probability of appearance.
- Parameters:
first – Range of elements to shuffle randomly.
last – Range of elements to shuffle randomly.