24#ifndef TVM_S_TIR_RANDOM_ENGINE_H_
25#define TVM_S_TIR_RANDOM_ENGINE_H_
27#include <tvm/ffi/error.h>
66 std::random_device rd;
82 return *rand_state_ptr_;
90 if (rand_state == -1) {
95 if (rand_state == 0) {
99 TVM_FFI_THROW(ValueError) <<
"Random seed must be non-negative";
108 TVM_FFI_ICHECK(rand_state_ptr_ !=
nullptr);
119 return ((*
this)() * 32767) % 1999999973;
130 rand_state_ptr_ = rand_state_ptr;
This linear congruential engine is a drop-in replacement for std::minstd_rand. It strictly correspond...
Definition random_engine.h:45
static constexpr TRandState multiplier
The multiplier.
Definition random_engine.h:51
void Seed(TRandState rand_state)
Change the start random state of RNG with the seed of a new random state value.
Definition random_engine.h:107
LinearCongruentialEngine(TRandState *rand_state_ptr)
Construct a random number generator with a random state pointer.
Definition random_engine.h:129
TRandState ForkSeed()
Fork a new seed for another RNG from current random state.
Definition random_engine.h:116
static constexpr TRandState modulus
The modulus.
Definition random_engine.h:55
static TRandState DeviceRandom()
Get a device random state.
Definition random_engine.h:65
uint64_t result_type
The result type.
Definition random_engine.h:49
result_type operator()()
Operator to move the random state to the next and return the new random state. According to definitio...
Definition random_engine.h:80
static TRandState NormalizeSeed(TRandState rand_state)
Normalize the random seed to the range of [1, modulus - 1].
Definition random_engine.h:89
static constexpr result_type max()
The maximum possible value of random state here.
Definition random_engine.h:59
int64_t TRandState
Definition random_engine.h:47
static constexpr result_type min()
The minimum possible value of random state here.
Definition random_engine.h:57
static constexpr TRandState increment
The increment.
Definition random_engine.h:53
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23