Template Class BasicRandomLocal#

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 BasicRandomLocal#

Base template class for random with local API and local internal member storage. It IS thread safe but less efficient then BasicRandomStatic.

Template Parameters:
  • engine – Random engine with interface like in the std::mt19937.

  • Seeder – Seeder type which return seed for internal engine through operator().

Public Types

using EngineType = engine#

Type of used random number engine.

using SeederType = Seeder#

Type of used random number seeder.

template<typename T>
using IntegerDistT = IntegerDist<T>#

Type of used integer distribution.

template<typename T>
using RealDistT = RealDist<T>#

Type of used real distribution.

using BoolDistT = BoolDist#

Type of used bool distribution.

using Common = INTERNAL::Common#

Key type for getting common type numbers or objects.

Public Functions

inline void Discard(const u64 z)#

Advances the internal state by z times.

Parameters:

z – How many times to advance.

inline void Reseed()#

Reseed by seeder.

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>
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.

inline engine::result_type Get()#

Retrieve a random number from engine in [Min(), Max()] range.

Returns:

Random number.

inline bool IsEqual(const engine &other) noexcept#

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>
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>
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:

istInput stream to extract the data from.

template<typename T>
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>
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>
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>
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:

Random common_type number in a [from; to] range.

template<typename T>
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>
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>
inline T Get(std::initializer_list<T> init_list)#

Retrieve random value from initializer_list.

Parameters:

init_list – initializer_list with values.

Returns:

Random value from initializer_list.

template<typename InputIt> inline ::value InputIt Get (InputIt first, InputIt last)

Retrieve random iterator from iterator range.

Parameters:
  • first – Range of elements.

  • last – Range of elements.

Returns:

Random iterator from [first, last) range.

template<typename Container>
inline Container::iterator Get(Container &container)#

Retrieve random iterator from container.

Template Parameters:

Container – Container with elements.

Parameters:

container – Container with elements.

Returns:

Random iterator from container.

template<typename T, usize N>
inline T *Get(T (&array)[N])#

Retrieve 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>
inline Dist::result_type Get(Args&&... args)#

Retrieve 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>
inline Dist::result_type Get(Dist &dist)#

Retrieve 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>
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>
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.

inline engine GetEngine() const noexcept#

Retrieve internal engine by copy.

Returns:

Internal engine.

inline engine &Engine() noexcept#

Retrieve internal engine by ref.

Returns:

Internal engine-

Public Static Functions

static inline constexpr engine::result_type Min()#

Retrieve the minimum value potentially generated by the random-number engine.

Returns:

Minimum random number.

static inline constexpr engine::result_type Max()#

Retrieve the maximum value potentially generated by the random-number engine.

Returns:

Maximum random number.

Protected Attributes

engine m_engine = {MakeSeededEngine()}#

Random number engine.

Protected Static Functions

static inline engine MakeSeededEngine()#

Retrieve engine seeded by seeder.

Returns:

Seeded engine.