SolidUtils
Static Public Member Functions | List of all members
sl::Random Class Reference

The Random class provides wrappers around base 'random' functionality, such as getting a number within a given range, shuffling elements, or filling an array with large amounts of random data. This class assumes psuedo-randomness is sufficient and that performance is more important, and thus should not be used where unpredictability or uniform distribution is desired. More...

#include <Random.hpp>

Static Public Member Functions

template<typename T , typename URBG >
static T inRange (T const min, T const max, URBG &&rng) noexcept
 Get a random number within the given range. The distribution may not be uniform. More...
 
template<typename T , typename URBG >
static void fillWithRange (T *const data, size_t const num, T const min, T const max, URBG &&rng) noexcept
 Fill a container with random numbers. If min and max are the same, an optimization is used where random is never called. If min is greater than max, the behavior is undefined (very bad). More...
 
template<typename T , typename URBG >
static void fillWithPerm (T *const data, size_t const num, T const offset, URBG &&rng) noexcept
 Fill a memory location with a permutation vector. More...
 
template<typename T , typename URBG >
static void pseudoShuffle (T *const data, size_t const num, URBG &&rng) noexcept
 Re-order the elements in array in a randomly. This is less random than std::shuffle, but is significantly faster for large arrays. More...
 

Detailed Description

The Random class provides wrappers around base 'random' functionality, such as getting a number within a given range, shuffling elements, or filling an array with large amounts of random data. This class assumes psuedo-randomness is sufficient and that performance is more important, and thus should not be used where unpredictability or uniform distribution is desired.

Member Function Documentation

◆ fillWithPerm()

template<typename T , typename URBG >
static void sl::Random::fillWithPerm ( T *const  data,
size_t const  num,
T const  offset,
URBG &&  rng 
)
inlinestaticnoexcept

Fill a memory location with a permutation vector.

Template Parameters
TThe type of data.
URBGThe type of random source.
Parameters
dataThe range of elements to fill.
beginThe starting index.

◆ fillWithRange()

template<typename T , typename URBG >
static void sl::Random::fillWithRange ( T *const  data,
size_t const  num,
T const  min,
T const  max,
URBG &&  rng 
)
inlinestaticnoexcept

Fill a container with random numbers. If min and max are the same, an optimization is used where random is never called. If min is greater than max, the behavior is undefined (very bad).

Template Parameters
TThe type of iterator.
URBGThe type of random source.
Parameters
rangeThe range of elements to fill.
minThe minimum number (inclusive).
maxThe maximum number (exclusive).
rngThe random source.

◆ inRange()

template<typename T , typename URBG >
static T sl::Random::inRange ( T const  min,
T const  max,
URBG &&  rng 
)
inlinestaticnoexcept

Get a random number within the given range. The distribution may not be uniform.

Template Parameters
TThe type of random source.
URBGThe random source.
Parameters
minThe lower bound (inclusive).
maxThe upper bound (exclusive).
rngThe random source.

◆ pseudoShuffle()

template<typename T , typename URBG >
static void sl::Random::pseudoShuffle ( T *const  data,
size_t const  num,
URBG &&  rng 
)
inlinestaticnoexcept

Re-order the elements in array in a randomly. This is less random than std::shuffle, but is significantly faster for large arrays.

Template Parameters
TThe type of elements.
URBGThe type of random source.
Parameters
dataThe data to shuffle.
numThe number of elements.
rngThe random source.

The documentation for this class was generated from the following file: