51 .AddAttribute(
"Stream",
52 "The stream number for this RNG stream. -1 means \"allocate a stream automatically\". "
53 "Note that if -1 is set, Get will return -1 so that it is not possible to know which "
54 "value was automatically allocated.",
58 MakeIntegerChecker<int64_t>())
59 .AddAttribute(
"Antithetic",
"Set this RNG stream to generate antithetic values",
112 uint64_t base = ((1ULL)<<63);
113 uint64_t target = base + stream;
140 static TypeId tid =
TypeId (
"ns3::UniformRandomVariable")
142 .AddConstructor<UniformRandomVariable> ()
143 .AddAttribute(
"Min",
"The lower bound on the values returned by this RNG stream.",
146 MakeDoubleChecker<double>())
147 .AddAttribute(
"Max",
"The upper bound on the values returned by this RNG stream.",
150 MakeDoubleChecker<double>())
177 double v = min +
Peek ()->
RandU01 () * (max - min);
189 return static_cast<uint32_t
> (
GetValue (min, max + 1) );
211 static TypeId tid =
TypeId (
"ns3::ConstantRandomVariable")
213 .AddConstructor<ConstantRandomVariable> ()
214 .AddAttribute(
"Constant",
"The constant value returned by this RNG stream.",
217 MakeDoubleChecker<double>())
266 static TypeId tid =
TypeId (
"ns3::SequentialRandomVariable")
268 .AddConstructor<SequentialRandomVariable> ()
269 .AddAttribute(
"Min",
"The first value of the sequence.",
272 MakeDoubleChecker<double>())
273 .AddAttribute(
"Max",
"One more than the last value of the sequence.",
276 MakeDoubleChecker<double>())
277 .AddAttribute(
"Increment",
"The sequence random variable increment.",
278 StringValue(
"ns3::ConstantRandomVariable[Constant=1]"),
280 MakePointerChecker<RandomVariableStream> ())
281 .AddAttribute(
"Consecutive",
"The number of times each member of the sequence is repeated.",
284 MakeIntegerChecker<uint32_t>());
291 m_currentConsecutive (0),
292 m_isCurrentSet (false)
366 static TypeId tid =
TypeId (
"ns3::ExponentialRandomVariable")
368 .AddConstructor<ExponentialRandomVariable> ()
369 .AddAttribute(
"Mean",
"The mean of the values returned by this RNG stream.",
372 MakeDoubleChecker<double>())
373 .AddAttribute(
"Bound",
"The upper bound on the values returned by this RNG stream.",
376 MakeDoubleChecker<double>())
413 double r = -mean*std::log (v);
416 if (bound == 0 || r <= bound)
426 return static_cast<uint32_t
> (
GetValue (mean, bound) );
448 static TypeId tid =
TypeId (
"ns3::ParetoRandomVariable")
450 .AddConstructor<ParetoRandomVariable> ()
451 .AddAttribute(
"Mean",
"The mean parameter for the Pareto distribution returned by this RNG stream.",
454 MakeDoubleChecker<double>())
455 .AddAttribute(
"Shape",
"The shape parameter for the Pareto distribution returned by this RNG stream.",
458 MakeDoubleChecker<double>())
459 .AddAttribute(
"Bound",
"The upper bound on the values returned by this RNG stream.",
462 MakeDoubleChecker<double>())
497 double scale = mean * (shape - 1.0) / shape;
509 double r = (scale * ( 1.0 / std::pow (v, 1.0 / shape)));
512 if (bound == 0 || r <= bound)
522 return static_cast<uint32_t
> (
GetValue (mean, shape, bound) );
544 static TypeId tid =
TypeId (
"ns3::WeibullRandomVariable")
546 .AddConstructor<WeibullRandomVariable> ()
547 .AddAttribute(
"Scale",
"The scale parameter for the Weibull distribution returned by this RNG stream.",
550 MakeDoubleChecker<double>())
551 .AddAttribute(
"Shape",
"The shape parameter for the Weibull distribution returned by this RNG stream.",
554 MakeDoubleChecker<double>())
555 .AddAttribute(
"Bound",
"The upper bound on the values returned by this RNG stream.",
558 MakeDoubleChecker<double>())
592 double exponent = 1.0 / shape;
603 double r = scale * std::pow ( -std::log (v), exponent);
606 if (bound == 0 || r <= bound)
616 return static_cast<uint32_t
> (
GetValue (scale, shape, bound) );
640 static TypeId tid =
TypeId (
"ns3::NormalRandomVariable")
642 .AddConstructor<NormalRandomVariable> ()
643 .AddAttribute(
"Mean",
"The mean value for the normal distribution returned by this RNG stream.",
646 MakeDoubleChecker<double>())
647 .AddAttribute(
"Variance",
"The variance value for the normal distribution returned by this RNG stream.",
650 MakeDoubleChecker<double>())
651 .AddAttribute(
"Bound",
"The bound on the values returned by this RNG stream.",
654 MakeDoubleChecker<double>())
706 double v1 = 2 * u1 - 1;
707 double v2 = 2 * u2 - 1;
708 double w = v1 * v1 + v2 * v2;
711 double y = std::sqrt ((-2 * std::log (w)) / w);
712 m_next = mean + v2 * y * std::sqrt (variance);
715 double x1 = mean + v1 * y * std::sqrt (variance);
717 if (std::fabs (x1 - mean) <= bound)
736 return static_cast<uint32_t
> (
GetValue (mean, variance, bound) );
758 static TypeId tid =
TypeId (
"ns3::LogNormalRandomVariable")
760 .AddConstructor<LogNormalRandomVariable> ()
761 .AddAttribute(
"Mu",
"The mu value for the log-normal distribution returned by this RNG stream.",
764 MakeDoubleChecker<double>())
765 .AddAttribute(
"Sigma",
"The sigma value for the log-normal distribution returned by this RNG stream.",
768 MakeDoubleChecker<double>())
841 r2 = v1 * v1 + v2 * v2;
843 while (r2 > 1.0 || r2 == 0);
845 normal = v1 * std::sqrt (-2.0 * std::log (r2) / r2);
847 x = std::exp (sigma * normal + mu);
856 return static_cast<uint32_t
> (
GetValue (mu, sigma));
880 .AddConstructor<GammaRandomVariable> ()
881 .AddAttribute(
"Alpha",
"The alpha value for the gamma distribution returned by this RNG stream.",
884 MakeDoubleChecker<double>())
885 .AddAttribute(
"Beta",
"The beta value for the gamma distribution returned by this RNG stream.",
888 MakeDoubleChecker<double>())
941 return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
945 double d = alpha - 1.0 / 3.0;
946 double c = (1.0 / 3.0) / std::sqrt (d);
955 double variance = 1.0;
969 if (u < 1 - 0.0331 * x * x * x * x)
973 if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
986 return static_cast<uint32_t
> (
GetValue (alpha, beta));
1022 double v1 = 2 * u1 - 1;
1023 double v2 = 2 * u2 - 1;
1024 double w = v1 * v1 + v2 * v2;
1027 double y = std::sqrt ((-2 * std::log (w)) / w);
1028 m_next = mean + v2 * y * std::sqrt (variance);
1031 double x1 = mean + v1 * y * std::sqrt (variance);
1033 if (std::fabs (x1 - mean) <= bound)
1054 static TypeId tid =
TypeId (
"ns3::ErlangRandomVariable")
1056 .AddConstructor<ErlangRandomVariable> ()
1057 .AddAttribute(
"K",
"The k value for the Erlang distribution returned by this RNG stream.",
1060 MakeIntegerChecker<uint32_t>())
1061 .AddAttribute(
"Lambda",
"The lambda value for the Erlang distribution returned by this RNG stream.",
1064 MakeDoubleChecker<double>())
1103 double mean = lambda;
1107 for (
unsigned int i = 0; i < k; ++i)
1120 return static_cast<uint32_t
> (
GetValue (k, lambda));
1150 double r = -mean*std::log (v);
1153 if (bound == 0 || r <= bound)
1166 static TypeId tid =
TypeId (
"ns3::TriangularRandomVariable")
1168 .AddConstructor<TriangularRandomVariable> ()
1169 .AddAttribute(
"Mean",
"The mean value for the triangular distribution returned by this RNG stream.",
1172 MakeDoubleChecker<double>())
1173 .AddAttribute(
"Min",
"The lower bound on the values returned by this RNG stream.",
1176 MakeDoubleChecker<double>())
1177 .AddAttribute(
"Max",
"The upper bound on the values returned by this RNG stream.",
1180 MakeDoubleChecker<double>())
1215 double mode = 3.0 * mean - min - max;
1225 if (u <= (mode - min) / (max - min) )
1227 return min + std::sqrt (u * (max - min) * (mode - min) );
1231 return max - std::sqrt ( (1 - u) * (max - min) * (max - mode) );
1239 return static_cast<uint32_t
> (
GetValue (mean, min, max) );
1263 .AddConstructor<ZipfRandomVariable> ()
1264 .AddAttribute(
"N",
"The n value for the Zipf distribution returned by this RNG stream.",
1267 MakeIntegerChecker<uint32_t>())
1268 .AddAttribute(
"Alpha",
"The alpha value for the Zipf distribution returned by this RNG stream.",
1271 MakeDoubleChecker<double>())
1300 for (uint32_t i = 1; i <= n; i++)
1302 m_c += (1.0 / std::pow ((
double)i,alpha));
1313 double sum_prob = 0,zipf_value = 0;
1314 for (uint32_t i = 1; i <=
m_n; i++)
1316 sum_prob +=
m_c / std::pow ((
double)i,
m_alpha);
1330 return static_cast<uint32_t
> (
GetValue (n, alpha));
1354 .AddConstructor<ZetaRandomVariable> ()
1355 .AddAttribute(
"Alpha",
"The alpha value for the zeta distribution returned by this RNG stream.",
1358 MakeDoubleChecker<double>())
1379 m_b = std::pow (2.0, alpha - 1.0);
1401 X = std::floor (std::pow (u, -1.0 / (
m_alpha - 1.0)));
1402 T = std::pow (1.0 + 1.0 / X,
m_alpha - 1.0);
1403 test = v * X * (T - 1.0) / (
m_b - 1.0);
1405 while ( test > (T /
m_b) );
1414 return static_cast<uint32_t
> (
GetValue (alpha));
1436 static TypeId tid =
TypeId (
"ns3::DeterministicRandomVariable")
1438 .AddConstructor<DeterministicRandomVariable> ()
1471 m_data =
new double[length];
1476 for (uint64_t i = 0; i <
m_count; i++)
1529 static TypeId tid =
TypeId (
"ns3::EmpiricalRandomVariable")
1531 .AddConstructor<EmpiricalRandomVariable> ()
1548 if (
emp.size () == 0)
1564 if (r <=
emp.front ().cdf)
1566 return emp.front ().value;
1568 if (r >=
emp.back ().cdf)
1570 return emp.back ().value;
1573 std::vector<ValueCDF>::size_type bottom = 0;
1574 std::vector<ValueCDF>::size_type top =
emp.size () - 1;
1577 std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
1578 if (r >=
emp[c].cdf && r <
emp[c + 1].cdf)
1581 emp[c].value,
emp[c + 1].value,
1614 for (std::vector<ValueCDF>::size_type i = 0; i <
emp.size (); ++i)
1619 std::cerr <<
"Empirical Dist error,"
1620 <<
" current value " << current.
value
1621 <<
" prior value " << prior.
value
1622 <<
" current cdf " << current.
cdf
1623 <<
" prior cdf " << prior.
cdf << std::endl;
1632 double v1,
double v2,
double r)
1635 return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
The Random Number Generator (RNG) that returns a predetermined sequence.
double m_scale
The scale parameter for the Weibull distribution returned by this RNG stream.
double m_current
The current sequence value.
ExponentialRandomVariable()
Creates a exponential distribution RNG with the default values for the mean and upper bound...
double GetSigma(void) const
Returns the sigma value for the log-normal distribution returned by this RNG stream.
double m_next
The algorithm produces two values at a time.
double GetAlpha(void) const
Returns the alpha value for the Zipf distribution returned by this RNG stream.
void SetAntithetic(bool isAntithetic)
Specifies whether antithetic values should be generated.
NormalRandomVariable()
Creates a normal distribution RNG with the default values for the mean, variance, and bound...
virtual double GetValue(void)
Returns the next value in the empirical distribution.
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
WeibullRandomVariable()
Creates a Weibull distribution RNG with the default values for the scale, shape, and upper bound...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Weibull distribution with the current scale, shape, and upper bound.
double GetAlpha(void) const
Returns the alpha value for the gamma distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from an exponential distribution with the current mean and upper bound...
double m_alpha
The alpha value for the Zipf distribution returned by this RNG stream.
double GetLambda(void) const
Returns the lambda value for the Erlang distribution returned by this RNG stream. ...
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double m_mean
The mean value for the triangular distribution returned by this RNG stream.
SequentialRandomVariable()
Creates a sequential RNG with the default values for the sequence parameters.
double m_bound
The upper bound on values that can be returned by this RNG stream.
static TypeId GetTypeId(void)
hold variables of type string
The exponential distribution Random Number Generator (RNG) that allows stream numbers to be set deter...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a triangular distribution with the current mean...
The Random Number Generator (RNG) that returns a sequential list of values.
The normal (Gaussian) distribution Random Number Generator (RNG) that allows stream numbers to be set...
uint64_t m_count
Position in the array of values.
double GetExponentialValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound...
#define NS_ASSERT(condition)
Hold a signed integer type.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
double m_mean
The mean parameter for the Pareto distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a normal distribution with the current mean, variance, and bound.
virtual ~DeterministicRandomVariable()
static TypeId GetTypeId(void)
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
uint32_t GetN(void) const
Returns the n value for the Zipf distribution returned by this RNG stream.
int64_t m_stream
The stream number for this RNG stream.
double m_constant
The constant value returned by this RNG stream.
double m_min
The first value of the sequence.
double GetConstant(void) const
Returns the constant value returned by this RNG stream.
double GetMin(void) const
Returns the first value of the sequence.
Ptr< RandomVariableStream > m_increment
The sequence random variable increment.
bool m_nextValid
True if the next value is valid.
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
#define NS_FATAL_ERROR(msg)
fatal error handling
static uint64_t GetRun(void)
virtual double Interpolate(double, double, double, double, double)
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
double m_bound
The upper bound on values that can be returned by this RNG stream.
DeterministicRandomVariable()
Creates a deterministic RNG that will have a predetermined sequence of values.
static TypeId GetTypeId(void)
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a gamma distribution with the current alpha and beta...
double m_shape
The shape parameter for the Pareto distribution returned by this RNG stream.
uint32_t m_n
The n value for the Zipf distribution returned by this RNG stream.
int64_t GetStream(void) const
Returns the stream number for this RNG stream.
virtual double GetValue(void)
Returns the next value in the sequence returned by this RNG stream.
RngStream * m_rng
Pointer to the underlying RNG stream.
Combined Multiple-Recursive Generator MRG32k3a.
double * m_data
Array of values to return in sequence.
Ptr< RandomVariableStream > GetIncrement(void) const
Returns the random variable increment for the sequence.
double m_lambda
The lambda value for the Erlang distribution returned by this RNG stream.
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
virtual double GetValue(void)
Returns the next value in the sequence.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Pareto distribution with the current mean, shape, and upper bound.
LogNormalRandomVariable()
Creates a log-normal distribution RNG with the default values for mu and sigma.
double GetScale(void) const
Returns the scale parameter for the Weibull distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a log-normal distribution with the current mu and sigma...
double GetMin(void) const
Returns the lower bound for the triangular distribution returned by this RNG stream.
uint32_t GetK(void) const
Returns the k value for the Erlang distribution returned by this RNG stream.
double m_max
One more than the last value of the sequence.
uint32_t GetConsecutive(void) const
Returns the number of times each member of the sequence is repeated.
ZetaRandomVariable()
Creates a zeta distribution RNG with the default value for alpha.
uint32_t m_k
The k value for the Erlang distribution returned by this RNG stream.
The gamma distribution Random Number Generator (RNG) that allows stream numbers to be set determinist...
static TypeId GetTypeId(void)
virtual double GetValue(void)
Returns a random double from a triangular distribution with the current mean, min, and max.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Zipf distribution with the current n and alpha...
void CDF(double v, double c)
Specifies a point in the empirical distribution.
virtual uint32_t GetInteger(void)
Returns an integer cast of the constant value returned by this RNG stream.
double m_sigma
The sigma value for the log-normal distribution returned by this RNG stream.
static TypeId GetTypeId(void)
ZipfRandomVariable()
Creates a Zipf distribution RNG with the default values for n and alpha.
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
GammaRandomVariable()
Creates a gamma distribution RNG with the default values for alpha and beta.
double GetMu(void) const
Returns the mu value for the log-normal distribution returned by this RNG stream. ...
uint64_t m_next
Position of the next value in the array of values.
static TypeId GetTypeId(void)
double m_c
The normalization constant.
uint32_t m_consecutive
The number of times each member of the sequence is repeated.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a normal distribution with the current mean, variance, and bound.
double GetMax(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
static TypeId GetTypeId(void)
double GetMean(void) const
Returns the mean value of the random variables returned by this RNG stream.
double m_mean
The mean value of the random variables returned by this RNG stream.
double GetVariance(void) const
Returns the variance value for the normal distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a Zipf distribution with the current n and alpha.
virtual double GetValue(void)
Returns the constant value returned by this RNG stream.
bool m_isCurrentSet
Indicates if the current sequence value has been set.
virtual double GetValue(void)
Returns a random double from an Erlang distribution with the current k and lambda.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
static const double INFINITE_VALUE
static TypeId GetTypeId(void)
uint32_t m_currentConsecutive
The number of times the sequence has been repeated.
double GetMean(void) const
Returns the mean value for the normal distribution returned by this RNG stream.
void SetValueArray(double *values, uint64_t length)
Sets the array of values that holds the predetermined sequence.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from an exponential distribution with the current mean and upper bo...
double m_bound
The upper bound on values that can be returned by this RNG stream.
EmpiricalRandomVariable()
Creates an empirical RNG that has a specified, empirical distribution.
double m_beta
The beta value for the gamma distribution returned by this RNG stream.
double RandU01(void)
Generate the next random number for this stream.
bool IsAntithetic(void) const
Returns true if antithetic values should be generated.
virtual double GetValue(void)
Returns a random double from a Weibull distribution with the current scale, shape, and upper bound.
double m_alpha
The alpha value for the gamma distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns the next value in the sequence.
static uint32_t GetSeed(void)
Get the seed value.
double GetNormalValue(double mean, double variance, double bound)
Returns a random double from a normal distribution with the specified mean, variance, and bound.
double GetMax(void) const
Returns one more than the last value of the sequence.
virtual double GetValue(void)
Returns a random double from a log-normal distribution with the current mu and sigma.
NS_LOG_COMPONENT_DEFINE("RandomVariableStream")
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a zeta distribution with the current alpha.
ParetoRandomVariable()
Creates a Pareto distribution RNG with the default values for the mean, the shape, and upper bound.
double GetBound(void) const
Returns the bound on values that can be returned by this RNG stream.
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
The Random Number Generator (RNG) that allows stream numbers to be set deterministically.
virtual uint32_t GetInteger(void)
Returns an integer cast of the next value in the sequence returned by this RNG stream.
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a zeta distribution with the current alpha.
double GetShape(void) const
Returns the shape parameter for the Weibull distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns the next value in the empirical distribution.
double m_bound
The bound on values that can be returned by this RNG stream.
double GetMean(void) const
Returns the mean parameter for the Pareto distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from an Erlang distribution with the current k and lambda...
virtual ~RandomVariableStream()
double m_next
The algorithm produces two normal values at a time.
RngStream * Peek(void) const
Returns a pointer to the underlying RNG stream.
double m_b
Just for calculus simplifications.
The triangular distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
static TypeId GetTypeId(void)
double m_max
The upper bound on values that can be returned by this RNG stream.
static TypeId GetTypeId(void)
ErlangRandomVariable()
Creates an Erlang distribution RNG with the default values for k and lambda.
bool m_nextValid
True if the next normal value is valid.
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
The Erlang distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
a base class which provides memory management and object aggregation
virtual double GetValue(void)
Returns a random double from a Pareto distribution with the current mean, shape, and upper bound...
static uint64_t GetNextStreamIndex(void)
The Random Number Generator (RNG) that has a specified empirical distribution.
double GetBeta(void) const
Returns the beta value for the gamma distribution returned by this RNG stream.
Hold a floating point type.
virtual double GetValue(void)
Returns a random double from a gamma distribution with the current alpha and beta.
double GetAlpha(void) const
Returns the alpha value for the zeta distribution returned by this RNG stream.
The log-normal distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
a unique identifier for an interface.
TriangularRandomVariable()
Creates a triangular distribution RNG with the default values for the mean, lower bound...
TypeId SetParent(TypeId tid)
ConstantRandomVariable()
Creates a constant RNG with the default constant value.
The Pareto distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
double GetMean(void) const
Returns the mean value for the triangular distribution returned by this RNG stream.
static TypeId GetTypeId(void)
double m_mu
The mu value for the log-normal distribution returned by this RNG stream.
double m_min
The lower bound on values that can be returned by this RNG stream.
The Random Number Generator (RNG) that returns a constant.
The Weibull distribution Random Number Generator (RNG) that allows stream numbers to be set determini...
The zeta distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
double GetShape(void) const
Returns the shape parameter for the Pareto distribution returned by this RNG stream.
std::vector< ValueCDF > emp
bool m_isAntithetic
Indicates if antithetic values should be generated by this RNG stream.