This linear congruential engine is a drop-in replacement for std::minstd_rand. It strictly corresponds to std::minstd_rand and is designed to be platform-independent.
More...
#include <random_engine.h>
|
result_type | operator() () |
| Operator to move the random state to the next and return the new random state. According to definition of linear congruential engine, the new random state value is computed as new_random_state = (current_random_state * multiplier + increment) % modulus. More...
|
|
void | Seed (TRandState rand_state) |
| Change the start random state of RNG with the seed of a new random state value. More...
|
|
TRandState | ForkSeed () |
| Fork a new seed for another RNG from current random state. More...
|
|
| LinearCongruentialEngine (TRandState *rand_state_ptr) |
| Construct a random number generator with a random state pointer. More...
|
|
This linear congruential engine is a drop-in replacement for std::minstd_rand. It strictly corresponds to std::minstd_rand and is designed to be platform-independent.
- Note
- Our linear congruential engine is a complete implementation of std::uniform_random_bit_generator so it can be used as generator for any STL random number distribution. However, parts of std::linear_congruential_engine's member functions are not included for simplification. For full member functions of std::minstd_rand, please check out the following link: https://en.cppreference.com/w/cpp/numeric/random/linear_congruential_engine
◆ result_type
◆ TRandState
◆ LinearCongruentialEngine()
tvm::support::LinearCongruentialEngine::LinearCongruentialEngine |
( |
TRandState * |
rand_state_ptr | ) |
|
|
inlineexplicit |
Construct a random number generator with a random state pointer.
- Parameters
-
rand_state_ptr | The random state pointer given in result_type*. |
- Note
- The random state is not checked for whether it's nullptr and whether it's in the range of [0, modulus-1]. We assume the given random state is valid or the Seed function would be called right after the constructor before any usage.
◆ DeviceRandom()
static TRandState tvm::support::LinearCongruentialEngine::DeviceRandom |
( |
| ) |
|
|
inlinestatic |
Get a device random state.
- Returns
- The random state
◆ ForkSeed()
TRandState tvm::support::LinearCongruentialEngine::ForkSeed |
( |
| ) |
|
|
inline |
Fork a new seed for another RNG from current random state.
- Returns
- The forked seed.
◆ max()
static constexpr result_type tvm::support::LinearCongruentialEngine::max |
( |
| ) |
|
|
inlinestaticconstexpr |
The maximum possible value of random state here.
◆ min()
static constexpr result_type tvm::support::LinearCongruentialEngine::min |
( |
| ) |
|
|
inlinestaticconstexpr |
The minimum possible value of random state here.
◆ NormalizeSeed()
Normalize the random seed to the range of [1, modulus - 1].
- Parameters
-
rand_state | The random seed. |
- Returns
- The normalized random seed.
◆ operator()()
result_type tvm::support::LinearCongruentialEngine::operator() |
( |
| ) |
|
|
inline |
Operator to move the random state to the next and return the new random state. According to definition of linear congruential engine, the new random state value is computed as new_random_state = (current_random_state * multiplier + increment) % modulus.
- Returns
- The next current random state value in the type of result_type.
- Note
- In order for better efficiency, the implementation here has a few assumptions:
- The multiplication and addition won't overflow.
- The given random state pointer
rand_state_ptr
is not nullptr.
- The given random state
*(rand_state_ptr)
is in the range of [0, modulus - 1].
◆ Seed()
void tvm::support::LinearCongruentialEngine::Seed |
( |
TRandState |
rand_state | ) |
|
|
inline |
Change the start random state of RNG with the seed of a new random state value.
- Parameters
-
rand_state | The random state given in result_type. |
◆ increment
constexpr TRandState tvm::support::LinearCongruentialEngine::increment = 0 |
|
staticconstexpr |
◆ modulus
constexpr TRandState tvm::support::LinearCongruentialEngine::modulus = 2147483647 |
|
staticconstexpr |
◆ multiplier
constexpr TRandState tvm::support::LinearCongruentialEngine::multiplier = 48271 |
|
staticconstexpr |
The documentation for this class was generated from the following file: