Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
Menge::Math::UniformIntGenerator Class Reference

An IntGenerator which returns a uniformly distributed value within a defined range. More...

#include <RandGenerator.h>

Inheritance diagram for Menge::Math::UniformIntGenerator:
Menge::Math::IntGenerator

Public Member Functions

 UniformIntGenerator (int minVal, int maxVal, int seed=0)
 Constructor. More...
 
void setRange (int minVal, int maxVal)
 Set the selection range. More...
 
virtual int getValue () const
 Return a value based on the integer generation rules. More...
 
virtual int getValueConcurrent () const
 Return a value based on the integer generation rules - performed in a thread-safe manner. More...
 
virtual void print (Logger &out) const
 Function for converting the generator to a string on a output stream. More...
 
virtual IntGeneratorcopy () const
 Create a copy of itself. More...
 
- Public Member Functions inherited from Menge::Math::IntGenerator
 IntGenerator ()
 Constructor.
 
virtual ~IntGenerator ()
 Virtual destructor.
 

Protected Attributes

int _min
 The lower end of the valid range.
 
int _size
 The size of the valid range.
 
int _seed
 A seed for the random number generator.
 
SimpleLock _lock
 The lock for guaranteeing threadsafe random number generation.
 

Friends

Loggeroperator<< (Logger &out, const UniformIntGenerator &gen)
 Friend function for writing string representation to an output stream. More...
 

Detailed Description

An IntGenerator which returns a uniformly distributed value within a defined range.

Constructor & Destructor Documentation

Menge::Math::UniformIntGenerator::UniformIntGenerator ( int  minVal,
int  maxVal,
int  seed = 0 
)

Constructor.

The value will lie within the range [minVal, maxVal]. All values in that range have equal probability of being selected.

Parameters
minValThe lower end of the valid range.
maxValThe upper end of the valid range.
seedIf the seed is zero, the global seed will be used otherwise the particular seed will be used.

Member Function Documentation

IntGenerator * Menge::Math::UniformIntGenerator::copy ( ) const
virtual

Create a copy of itself.

This is the basic functionality that must be overwridden by derived classes.

Returns
A pointer to a new generator which is a copy of this one. The caller of this function is responsible for freeing up the memory for the copy.

Implements Menge::Math::IntGenerator.

int Menge::Math::UniformIntGenerator::getValue ( ) const
virtual

Return a value based on the integer generation rules.

Returns
A uniformly distributed integer value.

Implements Menge::Math::IntGenerator.

int Menge::Math::UniformIntGenerator::getValueConcurrent ( ) const
virtual

Return a value based on the integer generation rules - performed in a thread-safe manner.

This is the basic functionality that must be overwridden by derived classes.

Returns
A integer value.

Implements Menge::Math::IntGenerator.

void Menge::Math::UniformIntGenerator::print ( Logger out) const
virtual

Function for converting the generator to a string on a output stream.

Parameters
outThe output stream to write the string representation to.

Implements Menge::Math::IntGenerator.

void Menge::Math::UniformIntGenerator::setRange ( int  minVal,
int  maxVal 
)
inline

Set the selection range.

Parameters
minValThe lower end of the valid range.
maxValThe upper end of the valid range.

Friends And Related Function Documentation

Logger& operator<< ( Logger out,
const UniformIntGenerator gen 
)
friend

Friend function for writing string representation to an output stream.

Parameters
outThe output stream.
genAn instance of the generator to represent as a string.
Returns
Reference to the input output stream.

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