gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
gem5::Random Class Reference

#include <random.hh>

Public Types

using RandomPtr = std::shared_ptr<Random>
 
using Instances = std::vector<std::weak_ptr<Random>>
 

Public Member Functions

 ~Random ()
 
void init (uint32_t s)
 
template<typename T>
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 point.
 
template<typename T>
std::enable_if_t< std::is_floating_point_v< T >, T > random ()
 
template<typename T>
std::enable_if_t< std::is_integral_v< T >, T > random (T min, T max)
 

Static Public Member Functions

static RandomPtr genRandom (Random *r=nullptr)
 
static RandomPtr genRandom (uint32_t s)
 
static void reseedAll (uint64_t seed)
 Facility to reseed all live instances and ensure future default constructed instances also use the new see.
 

Public Attributes

std::mt19937_64 gen
 

Static Public Attributes

static uint64_t globalSeed = 5489
 

Private Member Functions

 Random ()=delete
 
 Random (uint32_t s)
 
 Random (const Random &rng)=delete
 
Randomoperator= (const Random &rng)=delete
 
 Random (Random &&rng)=delete
 
Randomoperator= (Random &&rng)=delete
 

Static Private Attributes

static Instancesinstances = nullptr
 Collection of all live instances of Random to enable global reseeding.
 

Friends

class RandomTest
 

Detailed Description

Definition at line 60 of file random.hh.

Member Typedef Documentation

◆ Instances

using gem5::Random::Instances = std::vector<std::weak_ptr<Random>>

Definition at line 66 of file random.hh.

◆ RandomPtr

using gem5::Random::RandomPtr = std::shared_ptr<Random>

Definition at line 65 of file random.hh.

Constructor & Destructor Documentation

◆ ~Random()

gem5::Random::~Random ( )

Definition at line 54 of file random.cc.

References instances.

Member Function Documentation

◆ genRandom() [1/2]

static RandomPtr gem5::Random::genRandom ( Random * r = nullptr)
inlinestatic

◆ genRandom() [2/2]

static RandomPtr gem5::Random::genRandom ( uint32_t s)
inlinestatic

Definition at line 99 of file random.hh.

References instances, Random(), and gem5::ArmISA::s.

◆ init()

void gem5::Random::init ( uint32_t s)

Definition at line 74 of file random.cc.

References gen, and gem5::ArmISA::s.

◆ random()

template<typename T>
std::enable_if_t< std::is_floating_point_v< T >, T > gem5::Random::random ( )
inline

Definition at line 198 of file random.hh.

References gen, and warn_once.

◆ reseedAll()

static void gem5::Random::reseedAll ( uint64_t seed)
inlinestatic

Facility to reseed all live instances and ensure future default constructed instances also use the new see.

Definition at line 168 of file random.hh.

References globalSeed, and instances.

Referenced by gem5::pybind_init_core(), TEST(), and TEST().

Friends And Related Symbol Documentation

◆ RandomTest

friend class RandomTest
friend

Definition at line 62 of file random.hh.

References RandomTest.

Referenced by RandomTest.

Member Data Documentation

◆ globalSeed

uint64_t gem5::Random::globalSeed = 5489
static

Definition at line 120 of file random.hh.

Referenced by genRandom(), gem5::RandomTest::getGlobalSeed(), and reseedAll().

◆ instances

Random::Instances * gem5::Random::instances = nullptr
staticprivate

Collection of all live instances of Random to enable global reseeding.

We use a pointer because the loader will initialize it to 0x0 (it is in .bss), allowing us to avoid Static Initialization Order Fiasco if static Random instances are inialized before the vector by having the constructors of Random allocate memory for the pointer. This requires that nullptr matches how the loader initializes memory

Definition at line 142 of file random.hh.

Referenced by genRandom(), genRandom(), gem5::RandomTest::getInstances(), reseedAll(), and ~Random().


The documentation for this class was generated from the following files:

Generated on Mon May 26 2025 09:19:24 for gem5 by doxygen 1.13.2