45#ifndef __BASE_RANDOM_HH__
46#define __BASE_RANDOM_HH__
82 auto randpoint =
r ? std::shared_ptr<Random>(
r, [](
Random*){})
87 if (!weak_ptr.expired() && weak_ptr.lock() == randpoint) {
104 auto randpoint = std::shared_ptr<Random>(
new Random(
s));
107 for (
const auto& weak_ptr : *
instances) {
108 if (!weak_ptr.expired() && weak_ptr.lock() == randpoint) {
141 static_assert(
nullptr == 0x0,
"nullptr is not 0x0, Random instance tracking will fail");
161 void init(uint32_t
s);
176 rng_ptr.lock()->init(seed);
185 template <
typename T>
186 typename std::enable_if_t<std::is_integral_v<T>, T>
190 return gen() % std::numeric_limits<T>::max();
196 template <
typename T>
197 typename std::enable_if_t<std::is_floating_point_v<T>, T>
201 warn_once(
"FP random numbers are not uniformly distributed.");
203 ((T) std::numeric_limits<uint64_t>::max());
209 template <
typename T>
210 typename std::enable_if_t<std::is_integral_v<T>, T>
215 T
r =
gen() % (max - min + 1) + min;
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
static uint64_t globalSeed
std::vector< std::weak_ptr< Random > > Instances
static RandomPtr genRandom(Random *r=nullptr)
std::shared_ptr< Random > RandomPtr
static void reseedAll(uint64_t seed)
Facility to reseed all live instances and ensure future default constructed instances also use the ne...
static RandomPtr genRandom(uint32_t s)
static Instances * instances
Collection of all live instances of Random to enable global reseeding.
std::enable_if_t< std::is_floating_point_v< T >, T > random()
Random & operator=(const Random &rng)=delete
Random(const Random &rng)=delete
std::enable_if_t< std::is_integral_v< T >, T > random(T min, T max)
Random & operator=(Random &&rng)=delete
Random(Random &&rng)=delete
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
const FlagsType init
This Stat is Initialized.
Copyright (c) 2024 Arm Limited All rights reserved.