Template Struct unsafe_bits
Defined in File unsafe_bits.h
Struct Documentation
-
template<typename T>
struct unsafe_bits Return a random value of type T.
The structure is called “unsafe_bits” because it does not produce random bits suitable for cryptographic applications.
- Param T
[in] The (integer) type to generate bits for.
Public Types
-
using generator_type = typename std::conditional<sizeof(T) == 1, typename std::conditional<std::is_signed<T>::value, int16_t, uint16_t>::type, T>::type
For any integer smaller than 2 Bytes in size, we have to produce values from a 2 Byte type with the same sign. Here, we’re selecting the right type.
This construct selects the matching output type for the uniform distribution.
Public Functions
-
inline explicit unsafe_bits(T const &min = std::numeric_limits<T>::min(), T const &max = std::numeric_limits<T>::max())
Create an instance of a generator.
- Parameters
min – [in] optional minimum value; defaults to the
T's
minimum value.max – [in] optional maximum value; defaults to the
T's
maximum value.
-
inline T get()
- Returns
a random value of type
T
that is between the minimum and maximum specified in the constructor.
-
inline double get_factor()
- Returns
a random value as a factor. This treats the range of values given as the minimum and maximum in the constructor as [0,1] and returns a value between the two. The implication is that the maximum and minimum mostly describe the number of discrete values this function can produce.
Public Members
-
std::default_random_engine generator
Internal generator object.
-
std::uniform_int_distribution<generator_type> distribution
Internal uniform distribution object.