60 .AddAttribute(
"Stream",
61 "The stream number for this RNG stream. -1 means "
62 "\"allocate a stream automatically\". "
63 "Note that if -1 is set, Get will return -1 so that it "
64 "is not possible to know which "
65 "value was automatically allocated.",
69 MakeIntegerChecker<int64_t>())
70 .AddAttribute(
"Antithetic",
71 "Set this RNG stream to generate antithetic values",
131 uint64_t base = ((1ULL) << 63);
132 uint64_t target = base + stream;
158 TypeId(
"ns3::UniformRandomVariable")
160 .SetGroupName(
"Core")
163 "The lower bound on the values returned by this RNG stream.",
166 MakeDoubleChecker<double>())
168 "The upper bound on the values returned by this RNG stream.",
171 MakeDoubleChecker<double>());
234 static TypeId tid =
TypeId(
"ns3::ConstantRandomVariable")
236 .SetGroupName(
"Core")
238 .AddAttribute(
"Constant",
239 "The constant value returned by this RNG stream.",
242 MakeDoubleChecker<double>());
286 TypeId(
"ns3::SequentialRandomVariable")
288 .SetGroupName(
"Core")
291 "The first value of the sequence.",
294 MakeDoubleChecker<double>())
296 "One more than the last value of the sequence.",
299 MakeDoubleChecker<double>())
300 .AddAttribute(
"Increment",
301 "The sequence random variable increment.",
302 StringValue(
"ns3::ConstantRandomVariable[Constant=1]"),
304 MakePointerChecker<RandomVariableStream>())
305 .AddAttribute(
"Consecutive",
306 "The number of times each member of the sequence is repeated.",
309 MakeIntegerChecker<uint32_t>());
315 m_currentConsecutive(0),
316 m_isCurrentSet(false)
383 TypeId(
"ns3::ExponentialRandomVariable")
385 .SetGroupName(
"Core")
387 .AddAttribute(
"Mean",
388 "The mean of the values returned by this RNG stream.",
391 MakeDoubleChecker<double>())
392 .AddAttribute(
"Bound",
393 "The upper bound on the values returned by this RNG stream.",
396 MakeDoubleChecker<double>());
434 double r = -mean * std::log(v);
437 if (bound == 0 || r <= bound)
464 TypeId(
"ns3::ParetoRandomVariable")
466 .SetGroupName(
"Core")
470 "The scale parameter for the Pareto distribution returned by this RNG stream.",
473 MakeDoubleChecker<double>())
476 "The shape parameter for the Pareto distribution returned by this RNG stream.",
479 MakeDoubleChecker<double>())
482 "The upper bound on the values returned by this RNG stream (if non-zero).",
485 MakeDoubleChecker<double>());
533 double r = (scale * (1.0 / std::pow(v, 1.0 / shape)));
536 if (bound == 0 || r <= bound)
563 TypeId(
"ns3::WeibullRandomVariable")
565 .SetGroupName(
"Core")
569 "The scale parameter for the Weibull distribution returned by this RNG stream.",
572 MakeDoubleChecker<double>())
575 "The shape parameter for the Weibull distribution returned by this RNG stream.",
578 MakeDoubleChecker<double>())
579 .AddAttribute(
"Bound",
580 "The upper bound on the values returned by this RNG stream.",
583 MakeDoubleChecker<double>());
619 double exponent = 1.0 / shape;
630 double r = scale * std::pow(-std::log(v), exponent);
633 if (bound == 0 || r <= bound)
662 TypeId(
"ns3::NormalRandomVariable")
664 .SetGroupName(
"Core")
666 .AddAttribute(
"Mean",
667 "The mean value for the normal distribution returned by this RNG stream.",
670 MakeDoubleChecker<double>())
673 "The variance value for the normal distribution returned by this RNG stream.",
676 MakeDoubleChecker<double>())
677 .AddAttribute(
"Bound",
678 "The bound on the values returned by this RNG stream.",
681 MakeDoubleChecker<double>());
721 double x2 = mean +
m_v2 *
m_y * std::sqrt(variance);
722 if (std::fabs(x2 - mean) <= bound)
738 double v1 = 2 * u1 - 1;
739 double v2 = 2 * u2 - 1;
740 double w = v1 * v1 + v2 * v2;
743 double y = std::sqrt((-2 * std::log(w)) / w);
744 double x1 = mean + v1 * y * std::sqrt(variance);
746 if (std::fabs(x1 - mean) <= bound)
754 double x2 = mean + v2 * y * std::sqrt(variance);
755 if (std::fabs(x2 - mean) <= bound)
785 TypeId(
"ns3::LogNormalRandomVariable")
787 .SetGroupName(
"Core")
791 "The mu value for the log-normal distribution returned by this RNG stream.",
794 MakeDoubleChecker<double>())
797 "The sigma value for the log-normal distribution returned by this RNG stream.",
800 MakeDoubleChecker<double>());
860 return std::exp(sigma *
normal + mu);
887 r2 = v1 * v1 + v2 * v2;
888 }
while (r2 > 1.0 || r2 == 0);
890 m_normal = std::sqrt(-2.0 * std::log(r2) / r2);
895 x = std::exp(sigma *
normal + mu);
920 TypeId(
"ns3::GammaRandomVariable")
922 .SetGroupName(
"Core")
924 .AddAttribute(
"Alpha",
925 "The alpha value for the gamma distribution returned by this RNG stream.",
928 MakeDoubleChecker<double>())
929 .AddAttribute(
"Beta",
930 "The beta value for the gamma distribution returned by this RNG stream.",
933 MakeDoubleChecker<double>());
986 return GetValue(1.0 + alpha, beta) * std::pow(u, 1.0 / alpha);
992 double d = alpha - 1.0 / 3.0;
993 double c = (1.0 / 3.0) / std::sqrt(d);
1002 double variance = 1.0;
1015 if (u < 1 - 0.0331 * x * x * x * x)
1019 if (std::log(u) < 0.5 * x * x + d * (1 - v + std::log(v)))
1025 return beta * d * v;
1042 double x2 = mean +
m_v2 *
m_y * std::sqrt(variance);
1043 if (std::fabs(x2 - mean) <= bound)
1059 double v1 = 2 * u1 - 1;
1060 double v2 = 2 * u2 - 1;
1061 double w = v1 * v1 + v2 * v2;
1064 double y = std::sqrt((-2 * std::log(w)) / w);
1065 double x1 = mean + v1 * y * std::sqrt(variance);
1067 if (std::fabs(x1 - mean) <= bound)
1075 double x2 = mean + v2 * y * std::sqrt(variance);
1076 if (std::fabs(x2 - mean) <= bound)
1092 TypeId(
"ns3::ErlangRandomVariable")
1094 .SetGroupName(
"Core")
1097 "The k value for the Erlang distribution returned by this RNG stream.",
1100 MakeIntegerChecker<uint32_t>())
1103 "The lambda value for the Erlang distribution returned by this RNG stream.",
1106 MakeDoubleChecker<double>());
1146 double mean = lambda;
1150 for (
unsigned int i = 0; i < k; ++i)
1186 double r = -mean * std::log(v);
1189 if (bound == 0 || r <= bound)
1202 TypeId(
"ns3::TriangularRandomVariable")
1204 .SetGroupName(
"Core")
1208 "The mean value for the triangular distribution returned by this RNG stream.",
1211 MakeDoubleChecker<double>())
1212 .AddAttribute(
"Min",
1213 "The lower bound on the values returned by this RNG stream.",
1216 MakeDoubleChecker<double>())
1217 .AddAttribute(
"Max",
1218 "The upper bound on the values returned by this RNG stream.",
1221 MakeDoubleChecker<double>());
1258 double mode = 3.0 * mean -
min -
max;
1270 return min + std::sqrt(u * (
max -
min) * (mode -
min));
1274 return max - std::sqrt((1 - u) * (
max -
min) * (
max - mode));
1298 TypeId(
"ns3::ZipfRandomVariable")
1300 .SetGroupName(
"Core")
1303 "The n value for the Zipf distribution returned by this RNG stream.",
1306 MakeIntegerChecker<uint32_t>())
1307 .AddAttribute(
"Alpha",
1308 "The alpha value for the Zipf distribution returned by this RNG stream.",
1311 MakeDoubleChecker<double>());
1343 m_c += (1.0 / std::pow((
double)i, alpha));
1354 double sum_prob = 0;
1355 double zipf_value = 0;
1358 sum_prob +=
m_c / std::pow((
double)i,
m_alpha);
1388 TypeId(
"ns3::ZetaRandomVariable")
1390 .SetGroupName(
"Core")
1392 .AddAttribute(
"Alpha",
1393 "The alpha value for the zeta distribution returned by this RNG stream.",
1396 MakeDoubleChecker<double>());
1417 m_b = std::pow(2.0, alpha - 1.0);
1441 X = std::floor(std::pow(u, -1.0 / (
m_alpha - 1.0)));
1442 T = std::pow(1.0 + 1.0 / X,
m_alpha - 1.0);
1443 test = v * X * (T - 1.0) / (
m_b - 1.0);
1468 static TypeId tid =
TypeId(
"ns3::DeterministicRandomVariable")
1470 .SetGroupName(
"Core")
1510 m_data =
new double[length];
1515 for (std::size_t i = 0; i <
m_count; i++)
1563 TypeId(
"ns3::EmpiricalRandomVariable")
1565 .SetGroupName(
"Core")
1567 .AddAttribute(
"Interpolate",
1568 "Treat the CDF as a smooth distribution and interpolate, "
1569 "default is to treat the CDF as a histogram and sample.",
1611 if (r <=
m_emp.front().cdf)
1613 value =
m_emp.front().value;
1616 else if (r >=
m_emp.back().cdf)
1618 value =
m_emp.back().value;
1653 auto bound = std::upper_bound(
m_emp.begin(),
m_emp.end(), selector);
1655 return bound->value;
1684 auto upper = std::upper_bound(
m_emp.begin(),
m_emp.end(), selector);
1685 auto lower = std::prev(upper, 1);
1686 if (upper ==
m_emp.begin())
1692 double c1 = lower->cdf;
1693 double c2 = upper->cdf;
1694 double v1 = lower->value;
1695 double v2 = upper->value;
1697 double value = (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1707 m_emp.emplace_back(v, c);
1719 for (
auto current :
m_emp)
1721 if (current.value < prior.
value || current.cdf < prior.
cdf)
1723 std::cerr <<
"Empirical Dist error,"
1724 <<
" current value " << current.value <<
" prior value " << prior.
value
1725 <<
" current cdf " << current.cdf <<
" prior cdf " << prior.
cdf << std::endl;
1730 if (prior.
cdf != 1.0)
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::BooleanValue attribute value declarations.
AttributeValue implementation for Boolean.
The Random Number Generator (RNG) that returns a constant.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
ConstantRandomVariable()
Creates a constant RNG with the default constant value.
double GetConstant() const
Get the constant value returned by this RNG stream.
double m_constant
The constant value returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
The Random Number Generator (RNG) that returns a predetermined sequence.
double GetValue() override
Get the next random value drawn from the distribution.
std::size_t m_next
Position of the next value in the array of values.
void SetValueArray(const std::vector< double > &values)
Sets the array of values that holds the predetermined sequence.
~DeterministicRandomVariable() override
static TypeId GetTypeId()
Register this type.
double * m_data
Array of values to return in sequence.
DeterministicRandomVariable()
Creates a deterministic RNG that will have a predetermined sequence of values.
std::size_t m_count
Size of the array of values.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Helper to hold one point of the CDF.
double value
The argument value.
double cdf
The CDF at value
The Random Number Generator (RNG) that has a specified empirical distribution.
bool SetInterpolate(bool interpolate)
Switch the mode between sampling the CDF and interpolating.
void CDF(double v, double c)
Specifies a point in the empirical distribution.
bool PreSample(double &value)
Do the initial rng draw and check against the extrema.
double DoSampleCDF(double r)
Sample the CDF as a histogram (without interpolation).
double GetValue() override
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
bool m_interpolate
If true GetValue will interpolate, otherwise treat CDF as normal histogram.
bool m_validated
true once the CDF has been validated.
double DoInterpolate(double r)
Linear interpolation between two points on the CDF to estimate the value at r.
virtual double Interpolate()
Returns the next value in the empirical distribution using linear interpolation.
EmpiricalRandomVariable()
Creates an empirical RNG that has a specified, empirical distribution, and configured for interpolati...
std::vector< ValueCDF > m_emp
The vector of CDF points.
void Validate()
Check that the CDF is valid.
friend bool operator<(ValueCDF a, ValueCDF b)
Comparison operator, for use by std::upper_bound.
The Erlang distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
double m_lambda
The lambda value for the Erlang distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
double GetExponentialValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound.
static TypeId GetTypeId()
Register this type.
uint32_t GetK() const
Returns the k value for the Erlang distribution returned by this RNG stream.
double GetLambda() const
Returns the lambda value for the Erlang distribution returned by this RNG stream.
uint32_t m_k
The k value for the Erlang distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
ErlangRandomVariable()
Creates an Erlang distribution RNG with the default values for k and lambda.
The exponential distribution Random Number Generator (RNG).
ExponentialRandomVariable()
Creates an exponential distribution RNG with the default values for the mean and upper bound.
double GetBound() const
Get the configured upper bound of this RNG.
double m_mean
The mean value of the unbounded exponential distribution.
double GetMean() const
Get the configured mean value of this RNG.
double m_bound
The upper bound on values that can be returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
The gamma distribution Random Number Generator (RNG) that allows stream numbers to be set determinist...
double GetValue() override
Get the next random value drawn from the distribution.
GammaRandomVariable()
Creates a gamma distribution RNG with the default values for alpha and beta.
double m_alpha
The alpha value for the gamma distribution returned by this RNG stream.
double GetNormalValue(double mean, double variance, double bound)
Returns a random double from a normal distribution with the specified mean, variance,...
double m_y
The algorithm produces two values at a time.
double m_v2
The algorithm produces two values at a time.
bool m_nextValid
True if the next normal value is valid.
static TypeId GetTypeId()
Register this type.
double GetAlpha() const
Returns the alpha value for the gamma distribution returned by this RNG stream.
double GetBeta() const
Returns the beta value for the gamma distribution returned by this RNG stream.
double m_beta
The beta value for the gamma distribution returned by this RNG stream.
Hold a signed integer type.
The log-normal distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
double GetMu() const
Returns the mu value for the log-normal distribution returned by this RNG stream.
double m_v2
The algorithm produces two values at a time.
double GetSigma() const
Returns the sigma value for the log-normal distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
bool m_nextValid
True if m_normal is valid.
double m_mu
The mu value for the log-normal distribution returned by this RNG stream.
double m_sigma
The sigma value for the log-normal distribution returned by this RNG stream.
LogNormalRandomVariable()
Creates a log-normal distribution RNG with the default values for mu and sigma.
double m_normal
The algorithm produces two values at a time.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
The normal (Gaussian) distribution Random Number Generator (RNG) that allows stream numbers to be set...
double m_y
The algorithm produces two values at a time.
double GetBound() const
Returns the bound on values that can be returned by this RNG stream.
double GetVariance() const
Returns the variance value for the normal distribution returned by this RNG stream.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double GetMean() const
Returns the mean value for the normal distribution returned by this RNG stream.
static const double INFINITE_VALUE
Large constant to bound the range.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_bound
The bound on values that can be returned by this RNG stream.
bool m_nextValid
True if the next value is valid.
NormalRandomVariable()
Creates a normal distribution RNG with the default values for the mean, variance, and bound.
double m_v2
The algorithm produces two values at a time.
A base class which provides memory management and object aggregation.
The Pareto distribution Random Number Generator (RNG).
double GetShape() const
Returns the shape parameter for the Pareto distribution returned by this RNG stream.
double m_scale
The scale parameter for the Pareto distribution returned by this RNG stream.
ParetoRandomVariable()
Creates a Pareto distribution RNG with the default values for the mean, the shape,...
static TypeId GetTypeId()
Register this type.
double m_shape
The shape parameter for the Pareto distribution returned by this RNG stream.
double GetScale() const
Returns the scale parameter for the Pareto distribution returned by this RNG stream.
double m_bound
The upper bound on values that can be returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double GetValue() override
Get the next random value drawn from the distribution.
double GetBound() const
Returns the upper bound on values that can be returned by this RNG stream.
Smart pointer class similar to boost::intrusive_ptr.
The basic uniform Random Number Generator (RNG).
static TypeId GetTypeId()
Register this type.
RngStream * Peek() const
Get the pointer to the underlying RngStream.
bool IsAntithetic() const
Check if antithetic values will be generated.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
~RandomVariableStream() override
Destructor.
bool m_isAntithetic
Indicates if antithetic values should be generated by this RNG stream.
void SetAntithetic(bool isAntithetic)
Specify whether antithetic values should be generated.
int64_t m_stream
The stream number for the RngStream.
RandomVariableStream()
Default constructor.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
RngStream * m_rng
Pointer to the underlying RngStream.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
int64_t GetStream() const
Returns the stream number for the RngStream.
static uint64_t GetNextStreamIndex()
Get the next automatically assigned stream index.
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Combined Multiple-Recursive Generator MRG32k3a.
double RandU01()
Generate the next random number for this stream.
The Random Number Generator (RNG) that returns a pattern of sequential values.
uint32_t m_currentConsecutive
The number of times the current distinct value has been repeated.
double m_min
The first value of the sequence.
Ptr< RandomVariableStream > GetIncrement() const
Get the increment for the sequence.
uint32_t m_consecutive
The number of times each distinct value is repeated.
static TypeId GetTypeId()
Register this type.
double m_current
The current sequence value.
double m_max
Strict upper bound on the sequence.
Ptr< RandomVariableStream > m_increment
Increment between distinct values.
double GetValue() override
Get the next random value drawn from the distribution.
uint32_t GetConsecutive() const
Get the number of times each distinct value of the sequence is repeated before incrementing to the ne...
double GetMax() const
Get the limit of the sequence, which is (at least) one more than the last value of the sequence.
SequentialRandomVariable()
Creates a sequential RNG with the default values for the sequence parameters.
double GetMin() const
Get the first value of the sequence.
bool m_isCurrentSet
Indicates if the current sequence value has been properly initialized.
Hold variables of type string.
The triangular distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
double GetValue() override
Get the next random value drawn from the distribution.
double GetMean() const
Returns the mean value for the triangular distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double m_mean
The mean value for the triangular distribution returned by this RNG stream.
double m_max
The upper bound on values that can be returned by this RNG stream.
double GetMax() const
Returns the upper bound on values that can be returned by this RNG stream.
TriangularRandomVariable()
Creates a triangular distribution RNG with the default values for the mean, lower bound,...
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_min
The lower bound on values that can be returned by this RNG stream.
double GetMin() const
Returns the lower bound for the triangular distribution returned by this RNG stream.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
The Weibull distribution Random Number Generator (RNG) which allows stream numbers to be set determin...
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
double m_bound
The upper bound on values that can be returned by this RNG stream.
double m_scale
The scale parameter for the Weibull distribution returned by this RNG stream.
double GetBound() const
Returns the upper bound on values that can be returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
WeibullRandomVariable()
Creates a Weibull distribution RNG with the default values for the scale, shape, and upper bound.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
double GetScale() const
Returns the scale parameter for the Weibull distribution returned by this RNG stream.
double GetShape() const
Returns the shape parameter for the Weibull distribution returned by this RNG stream.
The zeta distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
static TypeId GetTypeId()
Register this type.
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
ZetaRandomVariable()
Creates a zeta distribution RNG with the default value for alpha.
double GetAlpha() const
Returns the alpha value for the zeta distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_b
Just for calculus simplifications.
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
uint32_t GetN() const
Returns the n value for the Zipf distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double m_c
The normalization constant.
double GetAlpha() const
Returns the alpha value for the Zipf distribution returned by this RNG stream.
ZipfRandomVariable()
Creates a Zipf distribution RNG with the default values for n and alpha.
double m_alpha
The alpha value for the Zipf distribution returned by this RNG stream.
uint32_t m_n
The n value for the Zipf distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double GetValue() override
Get the next random value drawn from the distribution.
ns3::DoubleValue attribute value declarations and template implementations.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
ns3::IntegerValue attribute value declarations and template implementations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ns3 Test suite for the ns3 wrapper script
ns3::PointerValue attribute value declarations and template implementations.
ns3::RandomVariableStream declaration, and related classes.
ns3::RngSeedManager declaration.
ns3::RngStream declaration.
ns3::StringValue attribute value declarations.