SUMO - Simulation of Urban MObility
RandHelper Class Reference

Utility functions for using a global, resetable random number generator. More...

#include <RandHelper.h>

Collaboration diagram for RandHelper:
Collaboration graph

Static Public Member Functions

template<class T >
static const T & getRandomFrom (const std::vector< T > &v)
 Returns a random element from the given vector. More...
 
static void initRandGlobal (MTRand *which=0)
 Reads the given random number options and initialises the random number generator in accordance. More...
 
static void insertRandOptions ()
 Initialises the given options container with random number options. More...
 
static double rand ()
 Returns a random real number in [0, 1) More...
 
static double rand (double maxV)
 Returns a random real number in [0, maxV) More...
 
static double rand (double minV, double maxV)
 Returns a random real number in [minV, maxV) More...
 
static int rand (int maxV)
 Returns a random integer in [0, maxV-1]. More...
 
static int rand (int minV, int maxV)
 Returns a random integer in [minV, maxV-1]. More...
 
static long long int rand (long long int maxV)
 Returns a random 64 bit integer in [0, maxV-1]. More...
 
static long long int rand (long long int minV, long long int maxV)
 Returns a random 64 bit integer in [minV, maxV-1]. More...
 
static double randNorm (double mean, double variance, MTRand *rng=0)
 Access to a random number from a normal distribution. More...
 

Static Protected Attributes

static MTRand myRandomNumberGenerator
 the random number generator to use More...
 

Detailed Description

Utility functions for using a global, resetable random number generator.

Definition at line 53 of file RandHelper.h.

Member Function Documentation

◆ getRandomFrom()

template<class T >
static const T& RandHelper::getRandomFrom ( const std::vector< T > &  v)
inlinestatic

Returns a random element from the given vector.

Definition at line 114 of file RandHelper.h.

References rand().

Referenced by MSEdge::getDepartLane(), MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS(), AGCity::getRandomStreet(), and AGAdult::randomFreeWorkPosition().

◆ initRandGlobal()

void RandHelper::initRandGlobal ( MTRand which = 0)
static

Reads the given random number options and initialises the random number generator in accordance.

Definition at line 64 of file RandHelper.cpp.

References OptionsCont::getBool(), OptionsCont::getInt(), OptionsCont::getOptions(), MTRand::hash(), myRandomNumberGenerator, and MTRand::seed().

Referenced by NLBuilder::loadAndRun(), main(), GNELoadThread::run(), and GUILoadThread::run().

◆ insertRandOptions()

◆ rand() [1/7]

static double RandHelper::rand ( )
inlinestatic

Returns a random real number in [0, 1)

Definition at line 62 of file RandHelper.h.

References myRandomNumberGenerator, and MTRand::randExc().

Referenced by RORouteDef::addAlternative(), RONet::addFlow(), MSBaseVehicle::calculateArrivalParams(), RONet::checkFlows(), MSVehicle::checkRewindLinkLanes(), MSSwarmTrafficLightLogic::choosePolicy(), ODMatrix::computeDeparts(), NGRandomNetBuilder::createNet(), NGRandomNetBuilder::createNewNode(), MSCFModel_Kerner::createVehicleVariables(), MSCFModel_Krauss::dawdle(), MSCFModel_Daniel1::dawdle(), MSCFModel_SmartSK::dawdle(), MSCFModel_KraussOrig1::dawdle(), MSCFModel_KraussX::dawdleX(), GLHelper::debugVertices(), AGPerson::decide(), MSSwarmTrafficLightLogic::decidePolicy(), AGFreeTime::decideTypeOfTrip(), MSInsertionControl::determineCandidates(), MSCFModel_PWag2009::followSpeed(), AGHousehold::generateCars(), AGWorkPosition::generateClosingTime(), AGWorkPosition::generateOpeningTime(), AGCity::generatePopulation(), AGActivities::generateRandomTraffic(), RandomDistributor< MSVehicleType *>::get(), MSLane::getDepartSpeed(), MSDevice_Routing::getEffort(), AGDataAndStatistics::getInverseExpRandomValue(), AGDataAndStatistics::getPoissonsNumberOfChildren(), AGDataAndStatistics::getRandom(), AGDataAndStatistics::getRandomCityGateByIncoming(), AGDataAndStatistics::getRandomCityGateByOutgoing(), getRandomFrom(), AGDataAndStatistics::getRandomPopDistributed(), MSLane::insertVehicle(), MSEdge::insertVehicle(), MSSOTLTrafficLightLogic::isThresholdPassed(), MSCFModel_Kerner::moveHelper(), MSTriggeredRerouter::notifyEnter(), MESegment::overtake(), rand(), AGPosition::randomPositionInStreet(), AGActivity::randomTimeBetween(), MELoop::setApproaching(), SigmoidLogic::sigmoidLogic(), NGNet::toNB(), MSCFModel_SmartSK::updateMyHeadway(), and MSPModel_Striping::PState::walk().

◆ rand() [2/7]

static double RandHelper::rand ( double  maxV)
inlinestatic

Returns a random real number in [0, maxV)

Definition at line 67 of file RandHelper.h.

References rand().

◆ rand() [3/7]

static double RandHelper::rand ( double  minV,
double  maxV 
)
inlinestatic

Returns a random real number in [minV, maxV)

Definition at line 72 of file RandHelper.h.

References rand().

◆ rand() [4/7]

static int RandHelper::rand ( int  maxV)
inlinestatic

Returns a random integer in [0, maxV-1].

Definition at line 77 of file RandHelper.h.

References myRandomNumberGenerator, and MTRand::randInt().

◆ rand() [5/7]

static int RandHelper::rand ( int  minV,
int  maxV 
)
inlinestatic

Returns a random integer in [minV, maxV-1].

Definition at line 82 of file RandHelper.h.

References rand().

◆ rand() [6/7]

static long long int RandHelper::rand ( long long int  maxV)
inlinestatic

Returns a random 64 bit integer in [0, maxV-1].

Definition at line 87 of file RandHelper.h.

References myRandomNumberGenerator, and MTRand::randInt64().

◆ rand() [7/7]

static long long int RandHelper::rand ( long long int  minV,
long long int  maxV 
)
inlinestatic

Returns a random 64 bit integer in [minV, maxV-1].

Definition at line 92 of file RandHelper.h.

References rand().

◆ randNorm()

static double RandHelper::randNorm ( double  mean,
double  variance,
MTRand rng = 0 
)
inlinestatic

Access to a random number from a normal distribution.

Definition at line 97 of file RandHelper.h.

References myRandomNumberGenerator, and MTRand::randExc().

Referenced by MSCFModel_Wiedemann::_v(), Distribution_Parameterized::sample(), and AGActivityGen::varDepTime().

Field Documentation

◆ myRandomNumberGenerator

MTRand RandHelper::myRandomNumberGenerator
staticprotected

the random number generator to use

Definition at line 122 of file RandHelper.h.

Referenced by initRandGlobal(), rand(), and randNorm().


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