Scippy

SoPlex

Sequential object-oriented simPlex

Random Class Reference

Random numbers.Class Random provides random Real variables, i.e. a value variable that gives another value each time it is accessed. It may be used just like an ordinary Real by means of an overloaded cast operator Real()%. More...

#include <random.h>

Public Member Functions

Access
Real min () const
 returns lower bound of random numbers.
 
Real max () const
 returns upper bound of random numbers.
 
 operator Real ()
 returns next random number.
 
Real last () const
 returns last random number or seed for next one.
 
Modification
void setMin (Real p_min)
 resets lower bound for random numbers.
 
void setMax (Real p_max)
 resets upper bound for random numbers.
 
void setSeed (Real seed)
 resets seed for next random number.
 
Debugging
bool isConsistent () const
 consistency check.
 
Constructors / destructors
 Random (Real p_min=0, Real p_max=1, Real p_seed=0.5)
 default constructor.
 
 ~Random ()
 destructor
 

Private Member Functions

Helpers
Real next_random ()
 increases rand seed and returns a pseudo random Real value in [0,1).
 
Real last_random () const
 returns the last used random value in [0,1).
 

Private Attributes

Data
Real themin
 minimum random number to be returned
 
Real themax
 maximum random number to be returned
 
unsigned long next
 random seed.
 

Detailed Description

Random numbers.

Class Random provides random Real variables, i.e. a value variable that gives another value each time it is accessed. It may be used just like an ordinary Real by means of an overloaded cast operator Real()%.

Definition at line 38 of file random.h.

Constructor & Destructor Documentation

Random ( Real  p_min = 0,
Real  p_max = 1,
Real  p_seed = 0.5 
)
explicit

default constructor.

Constructs a new (pseudo) Random variable returning values between p_min and p_max and using p_seed as seed for the random variable's sequence.

Definition at line 147 of file random.h.

References Random::isConsistent(), and Random::setSeed().

~Random ( )

destructor

Definition at line 157 of file random.h.

Member Function Documentation

bool isConsistent ( ) const

consistency check.

Definition at line 128 of file random.h.

References Random::themax, and Random::themin.

Referenced by Random::Random().

Real last ( ) const

returns last random number or seed for next one.

Definition at line 95 of file random.h.

References Random::last_random(), Random::themax, and Random::themin.

Real last_random ( ) const
private

returns the last used random value in [0,1).

Definition at line 61 of file random.h.

References Random::next, RDIVIDE, and RMULT.

Referenced by Random::last(), and Random::next_random().

Real max ( ) const

returns upper bound of random numbers.

Definition at line 79 of file random.h.

References Random::themax.

Real min ( ) const

returns lower bound of random numbers.

Definition at line 74 of file random.h.

References Random::themin.

Real next_random ( )
private

increases rand seed and returns a pseudo random Real value in [0,1).

Definition at line 54 of file random.h.

References Random::last_random(), Random::next, RADD, and RSTEP.

Referenced by Random::operator Real().

operator Real ( )

returns next random number.

When a Random variable is used where a Real value is expected, a new random number within the range specified in the constructor is retured.

Definition at line 89 of file random.h.

References Random::next_random(), Random::themax, and Random::themin.

void setMax ( Real  p_max)

resets upper bound for random numbers.

Definition at line 111 of file random.h.

References Random::themax.

void setMin ( Real  p_min)

resets lower bound for random numbers.

Definition at line 105 of file random.h.

References Random::themin.

void setSeed ( Real  seed)

resets seed for next random number.

Definition at line 117 of file random.h.

References Random::next, RDIVIDE, RMULT, Random::themax, and Random::themin.

Referenced by Random::Random().

Member Data Documentation

unsigned long next
private

random seed.

Definition at line 47 of file random.h.

Referenced by Random::last_random(), Random::next_random(), and Random::setSeed().

Real themax
private

maximum random number to be returned

Definition at line 46 of file random.h.

Referenced by Random::isConsistent(), Random::last(), Random::max(), Random::operator Real(), Random::setMax(), and Random::setSeed().

Real themin
private

minimum random number to be returned

Definition at line 45 of file random.h.

Referenced by Random::isConsistent(), Random::last(), Random::min(), Random::operator Real(), Random::setMin(), and Random::setSeed().