28 #include <sys/types.h>
115 : m_variable (o.m_variable->
Copy ())
119 : m_variable (variable.
Copy ())
186 double GetMin (
void)
const;
187 double GetMax (
void)
const;
197 virtual double GetValue (
double s,
double l);
253 return s + generator->
RandU01 () * (l -
s);
289 return static_cast<uint32_t
> (
GetValue (s, l + 1) );
450 m_currentConsecutive (0)
461 m_currentConsecutive (0)
470 m_increment (c.m_increment),
471 m_consecutive (c.m_consecutive),
472 m_current (c.m_current),
473 m_currentConsecutive (c.m_currentConsecutive)
710 : m_scale (0.5 / 1.5),
718 : m_scale (m * 0.5 / 1.5),
726 : m_scale (m * (s - 1.0) / s),
734 : m_scale (m * (s - 1.0) / s),
742 : m_scale (params.
first),
743 m_shape (params.second),
750 : m_scale (params.
first),
751 m_shape (params.second),
915 double exponent = 1.0 /
m_alpha;
918 double r =
m_mean * std::pow ( -std::log (generator->
RandU01 ()), exponent);
1003 m_bound (INFINITE_VALUE),
1021 m_variance (c.m_variance),
1022 m_bound (c.m_bound),
1041 double u1 = generator->
RandU01 ();
1042 double u2 = generator->
RandU01 ();
1043 double v1 = 2 * u1 - 1;
1044 double v2 = 2 * u2 - 1;
1045 double w = v1 * v1 + v2 * v2;
1048 double y = std::sqrt ((-2 * std::log (w)) / w);
1135 virtual void CDF (
double v,
double c);
1148 virtual double Interpolate (
double,
double,
double,
double,
double);
1185 validated (c.validated),
1201 if (
emp.size () == 0)
1209 double r = generator->
RandU01 ();
1210 if (r <=
emp.front ().cdf)
1212 return emp.front ().value;
1214 if (r >=
emp.back ().cdf)
1216 return emp.back ().value;
1219 std::vector<ValueCDF>::size_type bottom = 0;
1220 std::vector<ValueCDF>::size_type top =
emp.size () - 1;
1223 std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
1224 if (r >=
emp[c].cdf && r <
emp[c + 1].cdf)
1227 emp[c].value,
emp[c + 1].value,
1259 for (std::vector<ValueCDF>::size_type i = 0; i <
emp.size (); ++i)
1264 std::cerr <<
"Empirical Dist error,"
1265 <<
" current value " << current.
value
1266 <<
" prior value " << prior.
value
1267 <<
" current cdf " << current.
cdf
1268 <<
" prior cdf " << prior.
cdf << std::endl;
1277 double v1,
double v2,
double r)
1280 return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1318 virtual double Interpolate (
double,
double,
double,
double,
double);
1340 double v1,
double v2,
double r)
1343 return std::ceil (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1489 double u, v, r2,
normal, z;
1495 u = -1 + 2 * generator->
RandU01 ();
1496 v = -1 + 2 * generator->
RandU01 ();
1501 while (r2 > 1.0 || r2 == 0);
1503 normal = u * std::sqrt (-2.0 * std::log (r2) / r2);
1538 double GetValue (
double alpha,
double beta);
1593 double u = generator->
RandU01 ();
1594 return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
1598 double d = alpha - 1.0 / 3.0;
1599 double c = (1.0 / 3.0) / std::sqrt (d);
1612 if (u < 1 - 0.0331 * x * x * x * x)
1616 if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
1622 return beta * d * v;
1672 double GetValue (
unsigned int k,
double lambda);
1723 for (
unsigned int i = 0; i < k; ++i)
1803 m_mode (3.0 * mean - s - l)
1821 double u = generator->
RandU01 ();
1902 for (
int i = 1; i <= n; i++)
1904 m_c += (1.0 / std::pow ((
double)i, alpha));
1915 double u = generator->
RandU01 ();
1916 double sum_prob = 0,zipf_value = 0;
1917 for (
int i = 1; i <=
m_n; i++)
1919 sum_prob +=
m_c / std::pow ((
double)i,
m_alpha);
1979 m_b (std::pow (2.0, 2.14))
1987 m_b (std::pow (2.0, alpha - 1.0))
2011 X = floor (std::pow (u, -1.0 / (
m_alpha - 1.0)));
2012 T = std::pow (1.0 + 1.0 / X,
m_alpha - 1.0);
2013 test = v * X * (T - 1.0) / (
m_b - 1.0);
2015 while ( test > (T /
m_b) );
2039 os <<
"Constant:" << constant->
GetValue ();
2045 os <<
"Uniform:" << uniform->
GetMin () <<
":" << uniform->
GetMax ();
2052 double bound = normal->
GetBound ();
2060 os.setstate (std::ios_base::badbit);
2067 std::string::size_type tmp;
2068 tmp = value.find (
":");
2069 if (tmp == std::string::npos)
2071 is.setstate (std::ios_base::badbit);
2074 std::string type = value.substr (0, tmp);
2075 value = value.substr (tmp + 1, value.npos);
2076 if (type ==
"Constant")
2078 std::istringstream iss (value);
2083 else if (type ==
"Uniform")
2085 if (value.size () == 0)
2091 tmp = value.find (
":");
2092 if (tmp == value.npos)
2096 std::istringstream issA (value.substr (0, tmp));
2097 std::istringstream issB (value.substr (tmp + 1, value.npos));
2104 else if (type ==
"Normal")
2106 if (value.size () == 0)
2112 tmp = value.find (
":");
2113 if (tmp == value.npos)
2117 std::string::size_type tmp2;
2118 std::string sub = value.substr (tmp + 1, value.npos);
2119 tmp2 = sub.find (
":");
2120 if (tmp2 == value.npos)
2122 std::istringstream issA (value.substr (0, tmp));
2123 std::istringstream issB (sub);
2131 std::istringstream issA (value.substr (0, tmp));
2132 std::istringstream issB (sub.substr (0, tmp2));
2133 std::istringstream issC (sub.substr (tmp2 + 1, value.npos));
2144 NS_FATAL_ERROR (
"RandomVariable deserialization not implemented for " << type);
RandomVariableBase * Peek(void) const
virtual RandomVariableBase * Copy(void) const
virtual double GetValue()
ExponentialVariableImpl()
std::istream & operator>>(std::istream &is, Angles &a)
#define NS_LOG_FUNCTION(parameters)
A random variable that returns a constantClass ConstantVariable defines a random number generator tha...
virtual uint32_t GetInteger()
virtual uint32_t GetInteger()
virtual ~RandomVariableBase()
virtual double GetValue()
#define NS_ASSERT(condition)
virtual RandomVariableBase * Copy(void) const
uint32_t m_currentConsecutive
virtual double GetValue()
virtual RandomVariableBase * Copy() const
virtual RandomVariableBase * Copy(void) const
virtual double GetValue()
virtual double GetValue()
virtual double GetValue()
ATTRIBUTE_CHECKER_IMPLEMENT(Callback)
virtual RandomVariableBase * Copy(void) const
#define NS_FATAL_ERROR(msg)
fatal error handling
static uint64_t GetRun(void)
void NewConstant(double c)
Specify a new constant RNG for this generator.
Class NormalVariable defines a random variable with a normal (Gaussian) distribution.This class supports the creation of objects that return random numbers from a fixed normal distribution. It also supports the generation of single random numbers from various normal distributions.
virtual double Interpolate(double, double, double, double, double)
Combined Multiple-Recursive Generator MRG32k3a.
virtual RandomVariableBase * Copy(void) const
RandomVariable & operator=(const RandomVariable &o)
SequentialVariableImpl(double f, double l, double i=1, uint32_t c=1)
Constructor for the SequentialVariableImpl RNG.
virtual double GetValue()
DeterministicVariable(double *d, uint32_t c)
Constructor.
LogNormalVariableImpl(double mu, double sigma)
double GetValue(void) const
call RandomVariable::GetValue
virtual ~DeterministicVariableImpl()
SequentialVariable(double f, double l, double i=1, uint32_t c=1)
Constructor for the SequentialVariable RNG.
virtual RandomVariableBase * Copy(void) const =0
virtual RandomVariableBase * Copy(void) const
ErlangVariableImpl(unsigned int k, double lambda)
std::ostream & operator<<(std::ostream &os, const Angles &a)
LogNormalVariable(double mu, double sigma)
RandomVariableBase * m_variable
virtual RandomVariableBase * Copy(void) const
virtual double GetValue()
std::vector< ValueCDF > emp
RngStream * GetStream(void)
virtual RandomVariableBase * Copy(void) const
virtual RandomVariableBase * Copy(void) const
virtual void CDF(double v, double c)
Specifies a point in the empirical distribution.
virtual double GetValue()
Exponentially Distributed random varThis class supports the creation of objects that return random nu...
virtual RandomVariableBase * Copy(void) const
static uint32_t GetSeed(void)
Get the seed value.
virtual RandomVariableBase * Copy(void) const
RandomVariable m_increment
ATTRIBUTE_VALUE_IMPLEMENT(RandomVariable)
double GetValue(void) const
call RandomVariable::GetValue
virtual RandomVariableBase * Copy(void) const
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
double GetMean(void) const
void CDF(double v, double c)
Specifies a point in the empirical distribution.
virtual double GetValue()
virtual double GetValue()=0
virtual ~EmpiricalVariableImpl()
IntEmpiricalVariableImpl()
virtual double GetValue()
virtual uint32_t GetInteger()
GammaVariableImpl(double alpha, double beta)
static const double INFINITE_VALUE
virtual double GetValue()
double GetBound(void) const
DeterministicVariableImpl(double *d, uint32_t c)
Constructor.
double GetVariance(void) const
EmpiricalVariable distribution random varDefines a random variable that has a specified, empirical distribution. The distribution is specified by a series of calls to the CDF member function, specifying a value and the probability that the function value is less than the specified value. When values are requested, a uniform random variable is used to select a probability, and the return value is interpreted linearly between the two appropriate points in the CDF. The method is known as inverse transform sampling: (http://en.wikipedia.org/wiki/Inverse_transform_sampling).
static uint64_t GetNextStreamIndex(void)
The basic RNG for NS-3.Note: The underlying random number generation method used by NS-3 is the RngSt...
double GetValue(void) const
Returns a random double from the underlying distribution.
uint32_t GetInteger(void) const
Returns a random integer integer from the underlying distribution.
virtual double Interpolate(double, double, double, double, double)
virtual RandomVariableBase * Copy(void) const
virtual RandomVariableBase * Copy(void) const
void SetConstant(double c)
Specify a new constant RNG for this generator.
Ptr< T > Copy(Ptr< T > object)
~SequentialVariableImpl()
ParetoVariable()
Constructs a pareto random variable with a mean of 1 and a shape parameter of 1.5.
virtual double GetValue()
virtual double GetValue()