42unsigned long long int myDebugIndex(7);
43std::string myDebugId(
"");
46#ifdef DEBUG_RANDCALLS_PARALLEL
49std::map<std::thread::id, int> threadIndices;
50std::map<std::string, int> lastThreadIndex;
65 oc.
addDescription(
"random",
"Random Number",
TL(
"Initialises the random number generator with the current system time"));
69 oc.
addDescription(
"seed",
"Random Number",
TL(
"Initialises the random number generator with the given value"));
75 if (which ==
nullptr) {
79 which->seed((
unsigned long)time(
nullptr));
98 const double res = double((*rng)() / 4294967296.0);
100#ifdef DEBUG_RANDCALLS
101 if (rng->
count == myDebugIndex
102 && (myDebugId ==
"" || rng->
id == myDebugId)) {
103 std::cout <<
"DEBUG\n";
105 std::stringstream stream;
106#ifdef DEBUG_RANDCALLS_PARALLEL
107 auto threadID = std::this_thread::get_id();
108 if (threadIndices.count(threadID) == 0) {
109 const int tmp = threadIndices.size();
110 threadIndices[threadID] = tmp;
112 int threadIndex = threadIndices[threadID];
113 auto it = lastThreadIndex.find(rng->
id);
114 if ((it == lastThreadIndex.end() || it->second != threadIndex)
115 && (myDebugId ==
"" || rng->
id == myDebugId)) {
116 std::cout <<
"DEBUG rng " << rng->
id <<
" change thread old=" << (it == lastThreadIndex.end() ? -1 : it->second) <<
" new=" << threadIndex <<
" (" << std::this_thread::get_id() <<
")\n";
118 lastThreadIndex[rng->
id] = threadIndex;
119 stream <<
"rng " << rng->
id <<
" call=" << rng->
count <<
" thread=" << threadIndex <<
" val=" << res <<
"\n";
122 stream <<
"rng " << rng->
id <<
" call=" << rng->
count <<
" val=" << res <<
"\n";
123 std::cout << stream.str();
128 std::stringstream stream;
129 stream <<
"rng " << rng->
id <<
" call=" << rng->
count <<
" val=" << res <<
"\n";
130 std::cout << stream.str();
141 u =
rand(2.0, rng) - 1;
142 const double v =
rand(2.0, rng) - 1;
144 }
while (q == 0.0 || q >= 1.0);
145 const double logRounded = ceil(log(q) * 1e14) / 1e14;
146 return mean + variance * u * sqrt(-2 * logRounded / q);
151 return -log(
rand(rng)) / rate;
bool gDebugFlag1
global utility flags for debugging
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.
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 doRegister(const std::string &name, Option *o)
Adds an option under the given name.
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 OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
static SumoRNG myRandomNumberGenerator
the default random number generator to use
static double randExp(double rate, SumoRNG *rng=nullptr)
Access to a random number from an exponential distribution.
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 rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
static double randNorm(double mean, double variance, SumoRNG *rng=nullptr)
Access to a random number from a normal distribution.
static void insertRandOptions(OptionsCont &oc)
Initialises the given options container with random number options.
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
unsigned long long int count