Eclipse 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:

Static Public Member Functions

template<class T >
static const T & getRandomFrom (const std::vector< T > &v, std::mt19937 *rng=0)
 Returns a random element from the given vector. More...
 
static void initRand (std::mt19937 *which=0, const bool random=false, const int seed=23423)
 Initialises the random number generator with hardware randomness or seed. More...
 
static void initRandGlobal (std::mt19937 *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 void loadState (const std::string &state, std::mt19937 *rng=0)
 load rng state from string More...
 
static double rand (double maxV, std::mt19937 *rng=0)
 Returns a random real number in [0, maxV) More...
 
static double rand (double minV, double maxV, std::mt19937 *rng=0)
 Returns a random real number in [minV, maxV) More...
 
static int rand (int maxV, std::mt19937 *rng=0)
 Returns a random integer in [0, maxV-1]. More...
 
static int rand (int minV, int maxV, std::mt19937 *rng=0)
 Returns a random integer in [minV, maxV-1]. More...
 
static long long int rand (long long int maxV, std::mt19937 *rng=0)
 Returns a random 64 bit integer in [0, maxV-1]. More...
 
static long long int rand (long long int minV, long long int maxV, std::mt19937 *rng=0)
 Returns a random 64 bit integer in [minV, maxV-1]. More...
 
static double rand (std::mt19937 *rng=0)
 Returns a random real number in [0, 1) More...
 
static double randNorm (double mean, double variance, std::mt19937 *rng=0)
 Access to a random number from a normal distribution. More...
 
static std::string saveState (std::mt19937 *rng=0)
 save rng state to string More...
 

Static Protected Attributes

static int myCallCount
 only used for debugging; More...
 
static int myDebugIndex
 
static std::mt19937 myRandomNumberGenerator
 the random number generator to use More...
 

Detailed Description

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

Definition at line 48 of file RandHelper.h.

Member Function Documentation

◆ getRandomFrom()

template<class T >
static const T& RandHelper::getRandomFrom ( const std::vector< T > &  v,
std::mt19937 *  rng = 0 
)
inlinestatic

Returns a random element from the given vector.

Definition at line 154 of file RandHelper.h.

References rand().

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

◆ initRand()

void RandHelper::initRand ( std::mt19937 *  which = 0,
const bool  random = false,
const int  seed = 23423 
)
static

Initialises the random number generator with hardware randomness or seed.

Definition at line 59 of file RandHelper.cpp.

References myRandomNumberGenerator.

Referenced by initRandGlobal(), and MSLane::initRNGs().

◆ initRandGlobal()

void RandHelper::initRandGlobal ( std::mt19937 *  which = 0)
static

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

Definition at line 72 of file RandHelper.cpp.

References OptionsCont::getBool(), OptionsCont::getInt(), OptionsCont::getOptions(), and initRand().

Referenced by NLBuilder::initRandomness(), main(), MSInsertionControl::MSInsertionControl(), and GNELoadThread::run().

◆ insertRandOptions()

◆ loadState()

static void RandHelper::loadState ( const std::string &  state,
std::mt19937 *  rng = 0 
)
inlinestatic

load rng state from string

Definition at line 170 of file RandHelper.h.

References myRandomNumberGenerator.

Referenced by MSStateHandler::myStartElement().

◆ rand() [1/7]

static double RandHelper::rand ( double  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

Returns a random real number in [0, maxV)

Definition at line 76 of file RandHelper.h.

References rand().

◆ rand() [2/7]

static double RandHelper::rand ( double  minV,
double  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

Returns a random real number in [minV, maxV)

Definition at line 81 of file RandHelper.h.

References rand().

◆ rand() [3/7]

static int RandHelper::rand ( int  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

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

Definition at line 86 of file RandHelper.h.

References myRandomNumberGenerator.

◆ rand() [4/7]

static int RandHelper::rand ( int  minV,
int  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

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

Definition at line 106 of file RandHelper.h.

References rand().

◆ rand() [5/7]

static long long int RandHelper::rand ( long long int  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

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

Definition at line 111 of file RandHelper.h.

References myRandomNumberGenerator, and rand().

◆ rand() [6/7]

static long long int RandHelper::rand ( long long int  minV,
long long int  maxV,
std::mt19937 *  rng = 0 
)
inlinestatic

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

Definition at line 135 of file RandHelper.h.

References rand().

◆ rand() [7/7]

static double RandHelper::rand ( std::mt19937 *  rng = 0)
inlinestatic

Returns a random real number in [0, 1)

Definition at line 60 of file RandHelper.h.

References myCallCount, myDebugIndex, and myRandomNumberGenerator.

Referenced by MSLCM_LC2013::_wantsChange(), RORouteDef::addAlternative(), RONet::addFlow(), MSRouteHandler::addPersonTrip(), MSRouteHandler::addWalk(), MSLink::blockedAtTime(), NGEdge::buildNBEdge(), MSBaseVehicle::calculateArrivalParams(), RONet::checkFlows(), MSSwarmTrafficLightLogic::choosePolicy(), MSRouteHandler::closePersonFlow(), RORouteHandler::closePersonFlow(), ODMatrix::computeDeparts(), MSInsertionControl::computeRandomDepartOffset(), NGRandomNetBuilder::createNet(), NGRandomNetBuilder::createNewNode(), MSCFModel_Kerner::createVehicleVariables(), MSCFModel_KraussOrig1::dawdle(), MSCFModel_Daniel1::dawdle(), MSCFModel_SmartSK::dawdle(), MSCFModel_Krauss::dawdle2(), MSCFModel_KraussX::dawdleX(), AGPerson::decide(), MSSwarmTrafficLightLogic::decidePolicy(), AGFreeTime::decideTypeOfTrip(), MSInsertionControl::determineCandidates(), MSDevice::equippedByDefaultAssignmentOptions(), MSCFModel_Kerner::finalizeSpeed(), MSCFModel_W99::followSpeed(), MSCFModel_PWag2009::followSpeed(), AGHousehold::generateCars(), AGWorkPosition::generateClosingTime(), AGWorkPosition::generateOpeningTime(), AGCity::generatePopulation(), AGActivities::generateRandomTraffic(), RandomDistributor< SUMOVTypeParameter * >::get(), MSLane::getDepartPosLat(), MSLane::getDepartSpeed(), MSRoutingEngine::getEffortExtra(), AGDataAndStatistics::getInverseExpRandomValue(), AGDataAndStatistics::getPoissonsNumberOfChildren(), AGDataAndStatistics::getRandom(), AGDataAndStatistics::getRandomCityGateByIncoming(), AGDataAndStatistics::getRandomCityGateByOutgoing(), getRandomFrom(), AGDataAndStatistics::getRandomPopDistributed(), IntermodalEdge< E, L, N, V >::getTravelTimeStaticRandomized(), ROEdge::getTravelTimeStaticRandomized(), MSDevice_BTreceiver::inquiryDelaySlots(), MSLane::insertVehicle(), MSEdge::insertVehicle(), MSSOTLTrafficLightLogic::isThresholdPassed(), MSTriggeredRerouter::notifyEnter(), MSDevice_Bluelight::notifyMove(), MESegment::overtake(), SUMOVehicleParserHelper::parseWalkPos(), rand(), randNorm(), RGBColor::randomHue(), AGPosition::randomPositionInStreet(), AGActivity::randomTimeBetween(), MSTriggeredRerouter::rerouteParkingArea(), MELoop::setApproaching(), MSVehicle::setApproachingForAllLinks(), MSTransportable::Stage_Trip::setArrived(), GUILane::setFunctionalColor(), SigmoidLogic::sigmoidLogic(), NGNet::toNB(), MSCFModel_SmartSK::updateMyHeadway(), MSPModel_Striping::PState::walk(), and RODFDetector::writeEmitterDefinition().

◆ randNorm()

static double RandHelper::randNorm ( double  mean,
double  variance,
std::mt19937 *  rng = 0 
)
inlinestatic

Access to a random number from a normal distribution.

Definition at line 140 of file RandHelper.h.

References rand().

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

◆ saveState()

static std::string RandHelper::saveState ( std::mt19937 *  rng = 0)
inlinestatic

save rng state to string

Definition at line 160 of file RandHelper.h.

References myRandomNumberGenerator.

Referenced by MSStateHandler::saveRNGs().

Field Documentation

◆ myCallCount

int RandHelper::myCallCount
staticprotected

only used for debugging;

Definition at line 184 of file RandHelper.h.

Referenced by rand().

◆ myDebugIndex

int RandHelper::myDebugIndex
staticprotected

Definition at line 185 of file RandHelper.h.

Referenced by rand().

◆ myRandomNumberGenerator

std::mt19937 RandHelper::myRandomNumberGenerator
staticprotected

the random number generator to use

Definition at line 181 of file RandHelper.h.

Referenced by initRand(), loadState(), rand(), and saveState().


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