33 #ifdef DEBUG_RANDCALLS
34 std::map<SumoRNG*, int> RandHelper::myRngId;
35 int RandHelper::myDebugIndex(7);
50 oc.
addDescription(
"random",
"Random Number",
"Initialises the random number generator with the current system time");
54 oc.
addDescription(
"seed",
"Random Number",
"Initialises the random number generator with the given value");
60 if (which ==
nullptr) {
63 #ifdef DEBUG_RANDCALLS
64 myRngId[which] = myRngId.size();
67 which->seed((
unsigned long)time(
nullptr));
86 u =
rand(2.0, rng) - 1;
87 const double v =
rand(2.0, rng) - 1;
89 }
while (q == 0.0 || q >= 1.0);
90 const double logRounded = ceil(log(q) * 1e14) / 1e14;
91 return mean + variance * u * sqrt(-2 * logRounded / q);
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
static SumoRNG myRandomNumberGenerator
the default random number generator to use
static void initRand(SumoRNG *which=nullptr, const bool random=false, const int seed=23423)
Initialises the random number generator with hardware randomness or seed.
static double randNorm(double mean, double variance, SumoRNG *rng=nullptr)
Access to a random number from a normal distribution.
static void insertRandOptions()
Initialises the given options container with random number options.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.