Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Core::RandomGenerator Class Referenceexport

Singleton class providing centralized random number generation. More...

Public Member Functions

std::mt19937 getGenerator () const
 Gets a random number generator initialized with the global seed.
 
unsigned int getSeed () const
 Gets the currently set random seed.
 
void setSeed (unsigned int seed)
 Sets the global random seed.
 

Static Public Member Functions

static RandomGeneratorgetInstance ()
 Gets the singleton instance of the RandomGenerator.
 

Private Member Functions

 RandomGenerator ()
 
 RandomGenerator (const RandomGenerator &)=delete
 
RandomGeneratoroperator= (const RandomGenerator &)=delete
 

Private Attributes

std::mt19937 generator_
 
std::mutex mutex_
 
unsigned int seed_
 

Detailed Description

Singleton class providing centralized random number generation.

This class manages random number generation for the entire codebase, allowing control over reproducibility through seed management.

Constructor & Destructor Documentation

◆ RandomGenerator() [1/2]

Mila::Core::RandomGenerator::RandomGenerator ( )
inlineprivate

◆ RandomGenerator() [2/2]

Mila::Core::RandomGenerator::RandomGenerator ( const RandomGenerator )
privatedelete

Member Function Documentation

◆ getGenerator()

std::mt19937 Mila::Core::RandomGenerator::getGenerator ( ) const
inline

Gets a random number generator initialized with the global seed.

This returns a copy of the generator, so subsequent calls to setSeed won't affect already obtained generators.

Returns
A copy of the random number generator

◆ getInstance()

static RandomGenerator & Mila::Core::RandomGenerator::getInstance ( )
inlinestatic

Gets the singleton instance of the RandomGenerator.

Returns
Reference to the singleton instance
Here is the caller graph for this function:

◆ getSeed()

unsigned int Mila::Core::RandomGenerator::getSeed ( ) const
inline

Gets the currently set random seed.

Returns
The currently used seed value

◆ operator=()

RandomGenerator & Mila::Core::RandomGenerator::operator= ( const RandomGenerator )
privatedelete

◆ setSeed()

void Mila::Core::RandomGenerator::setSeed ( unsigned int  seed)
inline

Sets the global random seed.

Parameters
seedThe seed value (use 0 for non-deterministic behavior from std::random_device)
Here is the caller graph for this function:

Member Data Documentation

◆ generator_

std::mt19937 Mila::Core::RandomGenerator::generator_
private

◆ mutex_

std::mutex Mila::Core::RandomGenerator::mutex_
mutableprivate

◆ seed_

unsigned int Mila::Core::RandomGenerator::seed_
private

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