A Monte Carlo C++ code for radiative transport
Public Member Functions | Protected Attributes | List of all members
MCPP::BaseRandom Class Reference

The BaseRandom class is the base class for all the objects needing a RNG. More...

#include <MCPlusPlus/baserandom.h>

+ Inheritance diagram for MCPP::BaseRandom:
+ Collaboration diagram for MCPP::BaseRandom:

Public Member Functions

 BaseRandom (BaseObject *parent=NULL)
unsigned int currentSeed () const
 The seed currently used by the RNG. More...
void dumpGeneratorState (const char *fileName) const
 Dumps the RNG internal state to file. More...
string generatorState () const
 The RNG internal state. More...
void loadGeneratorState (const char *fileName)
 Loads a RNG state from file. More...
void setGeneratorState (string state)
 Set the internal RNG state. More...
void setSeed (unsigned int seed)
 Sets a new seed for the RNG. More...
- Public Member Functions inherited from MCPP::BaseObject
 BaseObject (BaseObject *parent=NULL)
list< BaseObject * > childList () const
BaseObjectclone () const
 Returns a cloned instance of the current object. More...
void describe () const
 Prints a description of the object and its main properties. More...
bool hasAParent () const
bool inheritsRandom () const
 Determines whether or not the object derives from BaseRandom. More...
BaseObjectparent () const
 Returns a pointer to the parent object.
bool sanityCheck () const
 Performs a series of integrity checks on internal data to ensure that the object is properly initialized and ready to be used. More...
void setParent (BaseObject *parent)
 Makes the object a child of parent. More...
string typeName () const
 The class name of the object. More...
bool wasCloned () const
 Determines whether or not the object was cloned. More...

Protected Attributes

unsigned int _currentSeed
MCEngine * mt
- Protected Attributes inherited from MCPP::BaseObject
bool _inheritsRandom
list< const BaseObject *const * > objectsToCheck

Additional Inherited Members

- Protected Member Functions inherited from MCPP::BaseObject
void addObjectToCheck (const BaseObject **const obj)
 Adds a BaseObject pointer to the list of objects to be checked. More...
void clearObjectsToCheck ()
void copyToInternalVariable (char **dest, const char *src)
void logMessage (const string &msg) const
 Logs a message to stderr. More...
void logMessage (const char *fmt,...) const

Detailed Description

The BaseRandom class is the base class for all the objects needing a RNG.

BaseRandom objects can be instantiated as stand-alone objects if they are created without specifying a parent. In this case they will use their own RNG which is initialized with setSeed(). Therefore it is mandatory to call setSeed() for stand-alone objects before any call to functions needing RNG.

If a parent / child relationship involving BaseRandom objects exists, then the following holds:

To sum up: parent / child relationships can be used to create objects which share the same instance of the RNG; this instance is created by calling setSeed() on the parent object. Again, calling setSeed() is mandatory to initialize the RNG, but it needs to be called only once (in the topmost BaseRandom parent).

The methods loadGeneratorState() and setGeneratorState() allow to specify a custom internal state of the RNG and can be used in place of setSeed(), with everything described above still holding.

Member Function Documentation

◆ currentSeed()

unsigned int BaseRandom::currentSeed ( ) const

The seed currently used by the RNG.


◆ dumpGeneratorState()

void BaseRandom::dumpGeneratorState ( const char *  fileName) const

Dumps the RNG internal state to file.


◆ generatorState()

string BaseRandom::generatorState ( ) const

The RNG internal state.


◆ loadGeneratorState()

void BaseRandom::loadGeneratorState ( const char *  fileName)

Loads a RNG state from file.


◆ setGeneratorState()

void BaseRandom::setGeneratorState ( string  state)

Set the internal RNG state.


Use generatorState() to obtain the RNG internal state of a BaseRandom object

◆ setSeed()

void BaseRandom::setSeed ( unsigned int  seed)

Sets a new seed for the RNG.


This function has no effect if the object has a parent of type BaseRandom. On the parent, this makes all child objects' RNG pointers point to the calling object's RNG.

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