Template Class BasicRandomThreadLocal#
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 BasicRandomThreadLocal# Base template class for random with thread_local API and thread_local internal member storage.
- Thread safety
This IS thread safe but less efficient than BasicRandomStatic.
- 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.
Public Functions
-
constexpr BasicRandomThreadLocal() = delete#
Constructor.
-
constexpr ~BasicRandomThreadLocal() = delete#
Destructor.
-
consteval BasicRandomThreadLocal(const BasicRandomThreadLocal&) = delete#
Copy constructor.
-
consteval BasicRandomThreadLocal operator=(const BasicRandomThreadLocal&) = delete#
Copy assignment operator.
-
consteval BasicRandomThreadLocal(BasicRandomThreadLocal&&) noexcept = delete#
Move constructor.
-
consteval BasicRandomThreadLocal operator=(BasicRandomThreadLocal&&) 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.
- Parameters:
seq – Seed sequence to use in the initialization of the internal state.
-
static inline engine::result_type Get()#
Retrieve 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, false otherwise
-
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:
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:
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:
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 – The 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:
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:
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)# Retrieve a random value from initializer_list.
- 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)
Retrieve a 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 Container::iterator Get(Container &container)# Retrieve a 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])# Retrieve a 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)# Retrieve a 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)# Retrieve a value from custom ‘dist’ distribution seeded by internal random engine.
- Template Parameters:
Dist – Custom distribution with next concept.
- 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.
-
template<typename Container>
static inline void Shuffle(Container &container)# Reorders the elements in the given container such that each possible permutation of those elements has equal probability of appearance.
- Template Parameters:
Container – Container with elements to shuffle randomly.
- Parameters:
container – Container with elements to shuffle randomly.