class RNG : public TclObject { enum RNGSources { RAW_SEED_SOURCE, PREDEF_SEED_SOURCE, HEURISTIC_SEED_SOURCE }; ... // These are primitive but maybe useful. inline int uniform_positive_int() { // range [0, MAXINT] return (int)(stream_.next()); } inline double uniform_double() { // range [0.0, 1.0) return stream_.next_double(); } inline int uniform(int k) { return (uniform_positive_int() % (unsigned)k); } inline double uniform(double r) { return (r * uniform_double());} inline double uniform(double a, double b) { return (a + uniform(b - a)); } inline double exponential() { return (-log(uniform_double())); } inline double exponential(double r) { return (r * exponential());} inline double pareto(double scale, double shape) { return (scale * (1.0/pow(uniform_double(), 1.0/shape)));} ... };
The uniform_positive_int method generates random integers in the range [0,231-1]. In particular, Additional member functions provide the following random variate generation:
The Random class (in random.h) is an older interface to the standard random number stream.
Here's a sample use of RNG modeled on RED. rng_ is an instance of class RNG:
\ldots // drop probability is computed, pick random number and act double u = rng_-\>uniform_double(); if (u \<= edv_.v_prob) { edv_.count = 0; if (edp_.setbit) iph-\>flags() |= IP_ECN; /* ip ecn bit / else return (1); } \ldots