PersonalRandomNumberGenerator Class Reference

CPP API: mio::abm::PersonalRandomNumberGenerator Class Reference
mio::abm::PersonalRandomNumberGenerator Class Reference

Random number generator of individual persons. More...

#include <personal_rng.h>

Inheritance diagram for mio::abm::PersonalRandomNumberGenerator:
Collaboration diagram for mio::abm::PersonalRandomNumberGenerator:

Public Member Functions

mio::Counter< uint64_t > get_counter () const
 
mio::Key< uint64_t > get_key () const
 
void increment_counter ()
 Increment the counter. More...
 
 PersonalRandomNumberGenerator (mio::Key< uint64_t > key, uint32_t index, mio::Counter< uint32_t > &counter)
 Creates a RandomNumberGenerator for a person. More...
 
 PersonalRandomNumberGenerator (Person &person)
 Creates a RandomNumberGenerator for a person. More...
 

Private Attributes

mio::Counter< uint32_t > & m_counter
 Reference to the Person's rng counter. More...
 
mio::Key< uint64_t > m_key
 Global RNG Key. More...
 
uint32_t m_person_index
 Index of the Person. More...
 

Detailed Description

Random number generator of individual persons.

Increments the random number generator counter of the person when used. Does not store its own key or counter. Instead the key needs to be provided from the outside, so that the RNG for all persons share the same key. The counter is taken from the person. PersonalRandomNumberGenerator is cheap to construct and transparent for the compiler to optimize, so we don't store the RNG persistently, only the counter, so we don't need to store the key in each person. This increases consistency (if the key is changed after the person is created) and reduces the memory required per person.

See also
mio::RandomNumberGeneratorBase

Constructor & Destructor Documentation

◆ PersonalRandomNumberGenerator() [1/2]

mio::abm::PersonalRandomNumberGenerator::PersonalRandomNumberGenerator ( mio::Key< uint64_t >  key,
uint32_t  index,
mio::Counter< uint32_t > &  counter 
)

Creates a RandomNumberGenerator for a person.

Parameters
keyKey to be used by the generator.
indexindex of the Person.
counterReference to the Person's RNG Counter.

◆ PersonalRandomNumberGenerator() [2/2]

mio::abm::PersonalRandomNumberGenerator::PersonalRandomNumberGenerator ( Person person)

Creates a RandomNumberGenerator for a person.

Parameters
personReference to the Person who's counter will be used.

Member Function Documentation

◆ get_counter()

mio::Counter<uint64_t> mio::abm::PersonalRandomNumberGenerator::get_counter ( ) const
inline
Returns
Get the current counter.

◆ get_key()

mio::Key<uint64_t> mio::abm::PersonalRandomNumberGenerator::get_key ( ) const
inline
Returns
Get the key.

◆ increment_counter()

void mio::abm::PersonalRandomNumberGenerator::increment_counter ( )
inline

Increment the counter.

Member Data Documentation

◆ m_counter

mio::Counter<uint32_t>& mio::abm::PersonalRandomNumberGenerator::m_counter
private

Reference to the Person's rng counter.

◆ m_key

mio::Key<uint64_t> mio::abm::PersonalRandomNumberGenerator::m_key
private

Global RNG Key.

◆ m_person_index

uint32_t mio::abm::PersonalRandomNumberGenerator::m_person_index
private

Index of the Person.