14 #include <ATen/Generator.h> 23 static void setSeed(int64_t seed);
29 static uint64_t
rand();
43 static auto sample(T&& distrib) -> decltype(distrib.min()) {
57 static at::Generator*
gen();
72 std::string
randId(
size_t length);
77 template <
typename Iter,
typename RandomGenerator>
79 std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
80 std::advance(start, dis(g));
std::string randId(size_t len)
Definition: rand.cpp:76
static thread_local std::unique_ptr< at::Generator > localTorchEngine_
Definition: rand.h:67
static std::mutex randEngineMutex_
Definition: rand.h:61
static std::mt19937 randEngine_
Definition: rand.h:60
static thread_local std::mt19937 localRandEngine_
Definition: rand.h:64
static T makeRandEngine()
Random number engine based on previously set seed.
Definition: rand.h:36
static at::Generator * gen()
This allows to use a custom seed in torch.
Definition: rand.cpp:69
static int64_t defaultRandomSeed()
Default random seed used by init()
Definition: rand.cpp:27
static std::unique_ptr< at::Generator > torchEngine_
Definition: rand.h:66
General utilities.
Definition: assert.cpp:7
static thread_local bool hasLocalSeed_
Definition: rand.h:63
static auto sample(T &&distrib) -> decltype(distrib.min())
Sample from a given distribution.
Definition: rand.h:43
static void setSeed(int64_t seed)
Set the seed for random generators: this one, rand(3) and ATen.
Definition: rand.cpp:31
static uint64_t rand()
Sample random value.
Definition: rand.cpp:61
static void setLocalSeed(int64_t seed)
Set a static seed for the local thread.
Definition: rand.cpp:48
Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
Definition: rand.h:78