A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
random-variable-stream.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 * Copyright (c) 2011 Mathieu Lacage
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Rajib Bhattacharjea<raj.b@gatech.edu>
8 * Hadi Arbabi<marbabi@cs.odu.edu>
9 * Mathieu Lacage <mathieu.lacage@gmail.com>
10 * Alessio Bugetti <alessiobugetti98@gmail.com>
11 *
12 * Modified by Mitch Watrous <watrous@u.washington.edu>
13 *
14 */
15#ifndef RANDOM_VARIABLE_STREAM_H
16#define RANDOM_VARIABLE_STREAM_H
17
18#include "attribute-helper.h"
19#include "object.h"
20#include "type-id.h"
21
22#include <limits>
23#include <map>
24#include <stdint.h>
25
26/**
27 * @file
28 * @ingroup randomvariable
29 * ns3::RandomVariableStream declaration, and related classes.
30 */
31
32namespace ns3
33{
34
35/**
36 * @ingroup core
37 * @defgroup randomvariable Random Variables
38 *
39 * @brief ns-3 random numbers are provided via instances of
40 * ns3::RandomVariableStream.
41 *
42 * - By default, ns-3 simulations use a fixed seed; if there is any
43 * randomness in the simulation, each run of the program will yield
44 * identical results unless the seed and/or run number is changed.
45 * - In ns-3.3 and earlier, ns-3 simulations used a random seed by default;
46 * this marks a change in policy starting with ns-3.4.
47 * - In ns-3.14 and earlier, ns-3 simulations used a different wrapper
48 * class called ns3::RandomVariable. This implementation is documented
49 * above under Legacy Random Variables. As of ns-3.15, this class has
50 * been replaced by ns3::RandomVariableStream; the underlying
51 * pseudo-random number generator has not changed.
52 * - To obtain randomness across multiple simulation runs, you must
53 * either set the seed differently or set the run number differently.
54 * To set a seed, call ns3::RngSeedManager::SetSeed() at the beginning
55 * of the program; to set a run number with the same seed, call
56 * ns3::RngSeedManager::SetRun() at the beginning of the program.
57 * - Each RandomVariableStream used in ns-3 has a virtual random number
58 * generator associated with it; all random variables use either
59 * a fixed or random seed based on the use of the global seed.
60 * - If you intend to perform multiple runs of the same scenario,
61 * with different random numbers, please be sure to read the manual
62 * section on how to perform independent replications.
63 */
64
65class RngStream;
66
67/**
68 * @ingroup randomvariable
69 * @brief The basic uniform Random Number Generator (RNG).
70 *
71 * @note The underlying random number generation method used
72 * by ns-3 is the RngStream code by Pierre L'Ecuyer at
73 * the University of Montreal.
74 *
75 * ns-3 has a rich set of random number generators that allow stream
76 * numbers to be set deterministically if desired. Class
77 * RandomVariableStream defines the base class functionality required
78 * for all such random number generators.
79 *
80 * By default, the underlying generator is seeded all the time with
81 * the same seed value and run number coming from the ns3::GlobalValue
82 * @ref GlobalValueRngSeed "RngSeed" and @ref GlobalValueRngRun
83 * "RngRun". Also by default, the stream number value for the
84 * underlying RngStream is automatically allocated.
85 *
86 * Instances can be configured to return "antithetic" values.
87 * See the documentation for the specific distributions to see
88 * how this modifies the returned values.
89 */
91{
92 public:
93 /**
94 * @brief Register this type.
95 * @return The object TypeId.
96 */
97 static TypeId GetTypeId();
98 /**
99 * @brief Default constructor.
100 */
102 /**
103 * @brief Destructor.
104 */
105 ~RandomVariableStream() override;
106
107 // Delete copy constructor and assignment operator to avoid misuse
110
111 /**
112 * @brief Specifies the stream number for the RngStream.
113 * @param [in] stream The stream number for the RngStream.
114 * -1 means "allocate a stream number automatically".
115 */
116 void SetStream(int64_t stream);
117
118 /**
119 * @brief Returns the stream number for the RngStream.
120 * @return The stream number for the RngStream.
121 * -1 means this stream was allocated automatically.
122 */
123 int64_t GetStream() const;
124
125 /**
126 * @brief Specify whether antithetic values should be generated.
127 * @param [in] isAntithetic If \c true antithetic value will be generated.
128 */
129 void SetAntithetic(bool isAntithetic);
130
131 /**
132 * @brief Check if antithetic values will be generated.
133 * @return \c true if antithetic values will be generated.
134 */
135 bool IsAntithetic() const;
136
137 /**
138 * @brief Get the next random value drawn from the distribution.
139 * @return A random value.
140 */
141 virtual double GetValue() = 0;
142
143 /** @copydoc GetValue() */
144 // The base implementation returns `(uint32_t)GetValue()`
145 virtual uint32_t GetInteger();
146
147 protected:
148 /**
149 * @brief Get the pointer to the underlying RngStream.
150 * @return The underlying RngStream
151 */
152 RngStream* Peek() const;
153
154 private:
155 /** Pointer to the underlying RngStream. */
157
158 /** Indicates if antithetic values should be generated by this RNG stream. */
160
161 /** The stream number for the RngStream. */
162 int64_t m_stream;
163
164 // end of class RandomVariableStream
165};
166
167/**
168 * @ingroup randomvariable
169 * @brief The uniform distribution Random Number Generator (RNG).
170 *
171 * This class supports the creation of objects that return random numbers
172 * from a fixed uniform distribution. It also supports the generation of
173 * single random numbers from various uniform distributions.
174 *
175 * The output range is \f$ x \in \f$ [\c Min, \c Max) for floating point values,
176 * (\c Max _excluded_), and \f$ x \in \f$ [\c Min, \c Max] (\c Max _included_)
177 * for integral values.
178 *
179 * This distribution has mean
180 *
181 * \f[
182 * \mu = \frac{\text{Max} + \text{Min}}{2}
183 * \f]
184 *
185 * and variance
186 *
187 * \f[
188 * \sigma^2 = \frac{\left(\text{Max} - \text{Min}\right)^2}{12}
189 * \f]
190 *
191 * The uniform RNG value \f$x\f$ is generated by
192 *
193 * \f[
194 * x = \text{Min} + u (\text{Max} - \text{Min})
195 * \f]
196 *
197 * where \f$u\f$ is a uniform random variable on [0,1).
198 *
199 * @par Example
200 *
201 * Here is an example of how to use this class:
202 * \code{.cc}
203 * double min = 0.0;
204 * double max = 10.0;
205 *
206 * Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
207 * x->SetAttribute ("Min", DoubleValue (min));
208 * x->SetAttribute ("Max", DoubleValue (max));
209 *
210 * double value = x->GetValue ();
211 * @endcode
212 *
213 * @par Antithetic Values.
214 *
215 * Normally this RNG returns values \f$x\f$ for floating point values
216 * (or \f$k\f$ for integer values) uniformly in the interval [\c Min, \c Max)
217 * (or [\c Min, \c Max] for integer values).
218 * If an instance of this RNG is configured to return antithetic values,
219 * the actual value returned is calculated as follows:
220 *
221 * - Compute the initial random value \f$x\f$ as normal.
222 * - Compute the distance from the maximum, \f$y = \text{Max} - x\f$
223 * - Return \f$x' = \text{Min} + y = \text{Min} + (\text{Max} - x)\f$:
224 */
226{
227 public:
228 /**
229 * @brief Register this type.
230 * @return The object TypeId.
231 */
232 static TypeId GetTypeId();
233
234 /**
235 * @brief Creates a uniform distribution RNG with the default range.
236 */
238
239 /**
240 * @brief Get the lower bound on randoms returned by GetValue().
241 * @return The lower bound on values from GetValue().
242 */
243 double GetMin() const;
244
245 /**
246 * @brief Get the upper bound on values returned by GetValue().
247 * @return The upper bound on values from GetValue().
248 */
249 double GetMax() const;
250
251 /**
252 * @copydoc GetValue()
253 *
254 * @param [in] min Low end of the range (included).
255 * @param [in] max High end of the range (excluded).
256 */
257 double GetValue(double min, double max);
258
259 /**
260 * @copydoc GetValue(double,double)
261 * @note The upper limit is included in the output range, unlike GetValue(double,double).
262 */
264
265 // Inherited
266 /**
267 * @copydoc RandomVariableStream::GetValue()
268 * @note The upper limit is excluded from the output range, unlike GetInteger().
269 */
270 double GetValue() override;
271
272 /**
273 * @copydoc RandomVariableStream::GetInteger()
274 * @note The upper limit is included in the output range, unlike GetValue().
275 */
276 uint32_t GetInteger() override;
277
278 private:
279 /** The lower bound on values that can be returned by this RNG stream. */
280 double m_min;
281
282 /** The upper bound on values that can be returned by this RNG stream. */
283 double m_max;
284
285 // end of class UniformRandomVariable
286};
287
288/**
289 * @ingroup randomvariable
290 * @brief The Random Number Generator (RNG) that returns a constant.
291 *
292 * This RNG returns the same \c Constant value for every sample.
293 *
294 * This distribution has mean equal to the \c Constant and zero variance.
295 *
296 * @par Antithetic Values.
297 *
298 * This RNG ignores the antithetic setting.
299 */
301{
302 public:
303 /**
304 * @brief Register this type.
305 * @return The object TypeId.
306 */
307 static TypeId GetTypeId();
308
309 /**
310 * @brief Creates a constant RNG with the default constant value.
311 */
313
314 /**
315 * @brief Get the constant value returned by this RNG stream.
316 * @return The constant value.
317 */
318 double GetConstant() const;
319
320 /**
321 * @copydoc GetValue()
322 * @param [in] constant The value to return.
323 */
324 double GetValue(double constant);
325 /** @copydoc GetValue(double) */
326 uint32_t GetInteger(uint32_t constant);
327
328 // Inherited
329 /*
330 * @copydoc RandomVariableStream::GetValue()
331 * @note This RNG always returns the same value.
332 */
333 double GetValue() override;
334 /* \note This RNG always returns the same value. */
336
337 private:
338 /** The constant value returned by this RNG stream. */
340
341 // end of class ConstantRandomVariable
342};
343
344/**
345 * @ingroup randomvariable
346 * @brief The Random Number Generator (RNG) that returns a pattern of
347 * sequential values.
348 *
349 * This RNG has four configuration attributes:
350 *
351 * - An increment, \c Increment.
352 * - A consecutive repeat number, \c Consecutive.
353 * - The minimum value, \c Min.
354 * - The maximum value, \c Max.
355 *
356 * The RNG starts at the \c Min value. Each return value is
357 * repeated \c Consecutive times, before advancing by the \c Increment,
358 * modulo the \c Max. In other words when the \c Increment would cause
359 * the value to equal or exceed \c Max it is reset to \c Min plus the
360 * remainder:
361 *
362 * \code{.cc}
363 * m_current += m_increment->GetValue();
364 * if (m_current >= m_max)
365 * {
366 * m_current = m_min + (m_current - m_max);
367 * }
368 * @endcode
369 *
370 * This RNG returns values in the range \f$ x \in [\text{Min}, \text{Max}) \f$.
371 * See the Example, below, for how this executes in practice.
372 *
373 * Note the \c Increment attribute is itself a RandomVariableStream,
374 * which enables more varied patterns than in the example given here.
375 *
376 * @par Example
377 *
378 * For example, if an instance is configured with:
379 *
380 * Attribute | Value
381 * :---------- | -----:
382 * Min | 2
383 * Max | 13
384 * Increment | 4
385 * Consecutive | 3
386 *
387 * The sequence will return this pattern:
388 *
389 * \f[
390 * x \in \\
391 * \underbrace{ 2, 2, 2, }_{\times 3} \\
392 * \underbrace{ 6, 6, 6, }_{\times 3} \\
393 * \underbrace{10, 10, 10, }_{\times 3} \\
394 * \underbrace{ 3, 3, 3, }_{\times 3} \\
395 * \dots
396 * \f]
397 *
398 * The last value (3) is the result of the update rule in the code snippet
399 * above, `2 + (14 - 13)`.
400 *
401 * @par Antithetic Values.
402 *
403 * This RNG ignores the antithetic setting.
404 */
406{
407 public:
408 /**
409 * @brief Register this type.
410 * @return The object TypeId.
411 */
412 static TypeId GetTypeId();
413
414 /**
415 * @brief Creates a sequential RNG with the default values
416 * for the sequence parameters.
417 */
419
420 /**
421 * @brief Get the first value of the sequence.
422 * @return The first value of the sequence.
423 */
424 double GetMin() const;
425
426 /**
427 * @brief Get the limit of the sequence, which is (at least)
428 * one more than the last value of the sequence.
429 * @return The limit of the sequence.
430 */
431 double GetMax() const;
432
433 /**
434 * @brief Get the increment for the sequence.
435 * @return The increment between distinct values for the sequence.
436 */
438
439 /**
440 * @brief Get the number of times each distinct value of the sequence
441 * is repeated before incrementing to the next value.
442 * @return The number of times each value is repeated.
443 */
444 uint32_t GetConsecutive() const;
445
446 // Inherited
447 double GetValue() override;
449
450 private:
451 /** The first value of the sequence. */
452 double m_min;
453
454 /** Strict upper bound on the sequence. */
455 double m_max;
456
457 /** Increment between distinct values. */
459
460 /** The number of times each distinct value is repeated. */
462
463 /** The current sequence value. */
464 double m_current;
465
466 /** The number of times the current distinct value has been repeated. */
468
469 /** Indicates if the current sequence value has been properly initialized. */
471
472 // end of class SequentialRandomVariable
473};
474
475/**
476 * @ingroup randomvariable
477 * @brief The exponential distribution Random Number Generator (RNG).
478 *
479 * This class supports the creation of objects that return random numbers
480 * from a fixed exponential distribution. It also supports the generation of
481 * single random numbers from various exponential distributions.
482 *
483 * The probability density function of an exponential variable
484 * is defined as:
485 *
486 * \f[
487 * P(x; \alpha) dx = \alpha e^{-\alpha x} dx, \\
488 * \quad x \in [0, +\infty)
489 * \f]
490 *
491 * where \f$ \alpha = \frac{1}{\mu} \f$
492 * and \f$\mu\f$ is the \c Mean configurable attribute. This distribution
493 * has variance \f$ \sigma^2 = \alpha^2 \f$.
494 *
495 * The exponential RNG value \f$x\f$ is generated by
496 *
497 * \f[
498 * x = - \frac{\log(u)}{\alpha} = - \text{Mean} \log(u)
499 * \f]
500 *
501 * where \f$u\f$ is a uniform random variable on [0,1).
502 *
503 * @par Bounded Distribution
504 *
505 * Since the exponential distributions can theoretically return unbounded
506 * values, it is sometimes useful to specify a fixed upper \c Bound. The
507 * bounded version is defined over the interval \f$[0,b]\f$ as:
508 *
509 * \f[
510 * P(x; \alpha, b) dx = \alpha e^{-\alpha x} dx, \\
511 * \quad x \in [0, b]
512 * \f]
513 *
514 * Note that in this case the true mean of the distribution is smaller
515 * than the nominal mean value:
516 *
517 * \f[
518 * \langle x | P(x; \alpha, b) \rangle = \frac{1}{\alpha} -
519 * \left(\frac{1}{\alpha} + b\right)\exp^{-\alpha b}
520 * \f]
521 *
522 * @par Example
523 *
524 * Here is an example of how to use this class:
525 * \code{.cc}
526 * double mean = 3.14;
527 * double bound = 0.0;
528 *
529 * Ptr<ExponentialRandomVariable> x = CreateObject<ExponentialRandomVariable> ();
530 * x->SetAttribute ("Mean", DoubleValue (mean));
531 * x->SetAttribute ("Bound", DoubleValue (bound));
532 *
533 * double value = x->GetValue ();
534 * @endcode
535 *
536 * @par Antithetic Values.
537 *
538 * If an instance of this RNG is configured to return antithetic values,
539 * the actual value returned, \f$x'\f$, is generated as follows:
540 *
541 * \f[
542 * x' = - \frac{\log(1 - u)}{\alpha} = - Mean \log(1 - u),
543 * \f]
544 *
545 * where \f$u\f$ is a uniform random variable on [0,1).
546 */
548{
549 public:
550 /**
551 * @brief Register this type.
552 * @return The object TypeId.
553 */
554 static TypeId GetTypeId();
555
556 /**
557 * @brief Creates an exponential distribution RNG with the default
558 * values for the mean and upper bound.
559 */
561
562 /**
563 * @brief Get the configured mean value of this RNG.
564 *
565 * @note This will not be the actual mean if the distribution is
566 * truncated by a bound.
567 * @return The configured mean value.
568 */
569 double GetMean() const;
570
571 /**
572 * @brief Get the configured upper bound of this RNG.
573 * @return The upper bound.
574 */
575 double GetBound() const;
576
577 /**
578 * @copydoc GetValue()
579 * @param [in] mean Mean value of the unbounded exponential distribution.
580 * @param [in] bound Upper bound on values returned.
581 */
582 double GetValue(double mean, double bound);
583
584 /** @copydoc GetValue(double,double) */
586
587 // Inherited
588 double GetValue() override;
590
591 private:
592 /** The mean value of the unbounded exponential distribution. */
593 double m_mean;
594
595 /** The upper bound on values that can be returned by this RNG stream. */
596 double m_bound;
597
598 // end of class ExponentialRandomVariable
599};
600
601/**
602 * @ingroup randomvariable
603 * @brief The Pareto distribution Random Number Generator (RNG).
604 *
605 * This class supports the creation of objects that return random numbers
606 * from a fixed Pareto distribution. It also supports the generation of
607 * single random numbers from various Pareto distributions.
608 *
609 * The probability density function of a Pareto variable is:
610 *
611 * \f[
612 * P(x; x_m, \alpha) dx = \alpha \frac{x_m^\alpha}{x^{\alpha + 1}} dx, \\
613 * \quad x \in [x_m, +\infty)
614 * \f]
615 *
616 * where the minimum value \f$x_m > 0\f$ is called the \c Scale parameter
617 * and \f$ \alpha > 0\f$ is called the Pareto index or \c Shape parameter.
618 *
619 * The resulting distribution will have mean
620 *
621 * \f[
622 * \mu = x_m \frac{\alpha}{\alpha - 1} \mbox{ for $\alpha > 1$}
623 * \f]
624 *
625 * and variance
626 *
627 * \f[
628 * \sigma^2 = x_m \frac{1}{(\alpha - 1)(\alpha - 2)} \mbox { for $\alpha > 2$}
629 * \f]
630 *
631 * The minimum value \f$x_m\f$ can be inferred from the desired mean \f$\mu\f$
632 * and the parameter \f$\alpha\f$ with the equation
633 *
634 * \f[
635 * x_m = \mu \frac{\alpha - 1}{\alpha} \mbox{ for $\alpha > 1$}
636 * \f]
637 *
638 * The Pareto RNG value \f$x\f$ is generated by
639 *
640 * \f[
641 * x = \frac{x_m}{u^{\frac{1}{\alpha}}}
642 * \f]
643 *
644 * where \f$u\f$ is a uniform random variable on [0,1).
645 *
646 * @par Bounded Distribution
647 *
648 * Since Pareto distributions can theoretically return unbounded
649 * values, it is sometimes useful to specify a fixed upper \c Bound. The
650 * bounded version is defined over the interval \f$ x \in [x_m, b] \f$.
651 * Note however when the upper limit is specified, the mean
652 * of the resulting distribution is slightly smaller than the mean value
653 * in the unbounded case.
654 *
655 * @par Example
656 *
657 * Here is an example of how to use this class:
658 * \code{.cc}
659 * double scale = 5.0;
660 * double shape = 2.0;
661 *
662 * Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
663 * x->SetAttribute ("Scale", DoubleValue (scale));
664 * x->SetAttribute ("Shape", DoubleValue (shape));
665 *
666 * double value = x->GetValue ();
667 * @endcode
668 *
669 * @par Antithetic Values.
670 *
671 * If an instance of this RNG is configured to return antithetic values,
672 * the actual value returned, \f$x'\f$, is generated as follows:
673 *
674 * \f[
675 * x' = \frac{x_m}{{(1 - u)}^{\frac{1}{\alpha}}} ,
676 * \f]
677 *
678 * which now involves the distance \f$u\f$ is from 1 in the denominator.
679 */
681{
682 public:
683 /**
684 * @brief Register this type.
685 * @return The object TypeId.
686 */
687 static TypeId GetTypeId();
688
689 /**
690 * @brief Creates a Pareto distribution RNG with the default
691 * values for the mean, the shape, and upper bound.
692 */
694
695 /**
696 * @brief Returns the scale parameter for the Pareto distribution returned by this RNG stream.
697 * @return The scale parameter for the Pareto distribution returned by this RNG stream.
698 */
699 double GetScale() const;
700
701 /**
702 * @brief Returns the shape parameter for the Pareto distribution returned by this RNG stream.
703 * @return The shape parameter for the Pareto distribution returned by this RNG stream.
704 */
705 double GetShape() const;
706
707 /**
708 * @brief Returns the upper bound on values that can be returned by this RNG stream.
709 * @return The upper bound on values that can be returned by this RNG stream.
710 */
711 double GetBound() const;
712
713 /**
714 * @copydoc GetValue()
715 * @param [in] scale Mean parameter for the Pareto distribution.
716 * @param [in] shape Shape parameter for the Pareto distribution.
717 * @param [in] bound Upper bound on values returned.
718 */
719 double GetValue(double scale, double shape, double bound);
720
721 /** @copydoc GetValue(double,double,double) */
722 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
723
724 // Inherited
725 double GetValue() override;
727
728 private:
729 /** The scale parameter for the Pareto distribution returned by this RNG stream. */
730 double m_scale;
731
732 /** The shape parameter for the Pareto distribution returned by this RNG stream. */
733 double m_shape;
734
735 /** The upper bound on values that can be returned by this RNG stream. */
736 double m_bound;
737
738 // end of class ParetoRandomVariable
739};
740
741/**
742 * @ingroup randomvariable
743 * @brief The Weibull distribution Random Number Generator (RNG)
744 * which allows stream numbers to be set deterministically.
745 *
746 * This class supports the creation of objects that return random numbers
747 * from a fixed Weibull distribution. It also supports the generation of
748 * single random numbers from various Weibull distributions.
749 *
750 * The probability density function is:
751 *
752 * \f[
753 * P(x; \lambda, k) dx = \frac{k}{\lambda} \\
754 * \left(\frac{x}{\lambda}\right)^{k-1} \\
755 * e^{-\left(\frac{x}{\lambda}\right)^k} dx, \\
756 * \quad x \in [0, +\infty)
757 * \f]
758 *
759 * where \f$ k > 0\f$ is the \c Shape parameter and \f$ \lambda > 0\f$
760 * is the \c Scale parameter.
761 *
762 * The mean \f$\mu\f$ is related to the \c Scale and \c Shape parameters
763 * by the following relation:
764 *
765 * \f[
766 * \mu = \lambda\Gamma\left(1+\frac{1}{k}\right)
767 * \f]
768 *
769 * where \f$ \Gamma \f$ is the Gamma function.
770 *
771 * The variance of the distribution is
772 *
773 * \f[
774 * \sigma^2 = \lambda^2 \left[ \Gamma\left(1 + \frac{2}{k}\right) - \\
775 * \left( \Gamma\left(1 + \frac{1}{k}\right)\right)^2
776 * \right]
777 * \f]
778 *
779 * For \f$ k > 1 \f$ the mean rapidly approaches just \f$\lambda\f$,
780 * with variance
781 *
782 * \f[
783 * \sigma^2 \approx \frac{\pi^2}{6 k^2} + \mathcal{O}(k^{-3})
784 * \f]
785 *
786 * The Weibull RNG value \f$x\f$ is generated by
787 *
788 * \f[
789 * x = \lambda {(-\log(u))}^{\frac{1}{k}}
790 * \f]
791 *
792 * where \f$u\f$ is a uniform random variable on [0,1).
793 *
794 * @par Bounded Distribution
795 *
796 * Since Weibull distributions can theoretically return unbounded values,
797 * it is sometimes useful to specify a fixed upper limit. The
798 * bounded version is defined over the interval \f$ x \in [0, b] \f$.
799 * Note however when the upper limit is specified, the mean of the
800 * resulting distribution is slightly smaller than the mean value
801 * in the unbounded case.
802 *
803 * @par Example
804 *
805 * Here is an example of how to use this class:
806 * \code{.cc}
807 * double scale = 5.0;
808 * double shape = 1.0;
809 *
810 * Ptr<WeibullRandomVariable> x = CreateObject<WeibullRandomVariable> ();
811 * x->SetAttribute ("Scale", DoubleValue (scale));
812 * x->SetAttribute ("Shape", DoubleValue (shape));
813 *
814 * double value = x->GetValue ();
815 * @endcode
816 *
817 * @par Antithetic Values.
818 *
819 * If an instance of this RNG is configured to return antithetic values,
820 * the actual value returned, \f$x'\f$, is generated as follows:
821 *
822 * \f[
823 * x' = \lambda {(-\log(1 - u))}^{\frac{1}{k}} ,
824 * \f]
825 *
826 * which now involves the log of the distance \f$u\f$ is from 1.
827 */
829{
830 public:
831 /**
832 * @brief Register this type.
833 * @return The object TypeId.
834 */
835 static TypeId GetTypeId();
836
837 /**
838 * @brief Creates a Weibull distribution RNG with the default
839 * values for the scale, shape, and upper bound.
840 */
842
843 /**
844 * @brief Returns the scale parameter for the Weibull distribution returned by this RNG stream.
845 * @return The scale parameter for the Weibull distribution returned by this RNG stream.
846 */
847 double GetScale() const;
848
849 /**
850 * @brief Returns the shape parameter for the Weibull distribution returned by this RNG stream.
851 * @return The shape parameter for the Weibull distribution returned by this RNG stream.
852 */
853 double GetShape() const;
854
855 /**
856 * @brief Returns the upper bound on values that can be returned by this RNG stream.
857 * @return The upper bound on values that can be returned by this RNG stream.
858 */
859 double GetBound() const;
860
861 /**
862 * @brief Returns the mean value for the Weibull distribution returned by this RNG stream.
863 * @return The mean value for the Weibull distribution returned by this RNG stream.
864 */
865 double GetMean() const;
866
867 /**
868 * @copydoc GetMean()
869 * @param [in] scale Scale parameter for the Weibull distribution.
870 * @param [in] shape Shape parameter for the Weibull distribution.
871 */
872 static double GetMean(double scale, double shape);
873
874 /**
875 * @copydoc GetValue()
876 * @param [in] scale Scale parameter for the Weibull distribution.
877 * @param [in] shape Shape parameter for the Weibull distribution.
878 * @param [in] bound Upper bound on values returned.
879 */
880 double GetValue(double scale, double shape, double bound);
881
882 /** @copydoc GetValue(double,double,double) */
883 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
884
885 // Inherited
886 double GetValue() override;
888
889 private:
890 /** The scale parameter for the Weibull distribution returned by this RNG stream. */
891 double m_scale;
892
893 /** The shape parameter for the Weibull distribution returned by this RNG stream. */
894 double m_shape;
895
896 /** The upper bound on values that can be returned by this RNG stream. */
897 double m_bound;
898
899 // end of class WeibullRandomVariable
900};
901
902/**
903 * @ingroup randomvariable
904 * @brief The normal (Gaussian) distribution Random Number Generator
905 * (RNG) that allows stream numbers to be set deterministically.
906 *
907 * This class supports the creation of objects that return random numbers
908 * from a fixed normal distribution. It also supports the generation of
909 * single random numbers from various normal distributions.
910 *
911 * The probability density function is:
912 *
913 * \f[
914 * P(x; \mu, \sigma) dx = \frac{1}{\sqrt{2\pi\sigma^2}}
915 * e^{-\frac{(x-\mu)^2}{2\sigma^2}} dx, \\
916 * \quad x \in (-\infty, +\infty)
917 * \f]
918 *
919 * where the \c Mean is given by \f$\mu\f$ and the \c Variance is \f$\sigma^2\f$
920 *
921 * If \f$u_1\f$, \f$u_2\f$ are uniform variables over [0,1]
922 * then the Gaussian RNG values, \f$x_1\f$ and \f$x_2\f$, are
923 * calculated as follows:
924 *
925 * \f{eqnarray*}{
926 * v_1 & = & 2 u_1 - 1 \\
927 * v_2 & = & 2 u_2 - 1 \\
928 * r^2 & = & v_1^2 + v_2^2 \\
929 * y & = & \sqrt{\frac{-2 \log(r^2)}{r^2}} \\
930 * x_1 & = & \mu + v_1 y \sqrt{\sigma^2} \\
931 * x_2 & = & \mu + v_2 y \sqrt{\sigma^2} .
932 * \f}
933 *
934 * Note this algorithm consumes two uniform random values and produces
935 * two normally distributed values. The implementation used here
936 * caches \f$y\f$ and \f$v_2\f$ to generate \f$x_2\f$ on the next call.
937 *
938 * @par Bounded Distribution
939 *
940 * Since normal distributions can theoretically return unbounded
941 * values, it is sometimes useful to specify a fixed bound. The
942 * NormalRandomVariable is bounded symmetrically about the mean by
943 * the \c Bound parameter, \f$b\f$, _i.e._ its values are confined to the interval
944 * \f$[\mu - b, \mu + b]\f$. This preserves the mean but decreases the variance.
945 *
946 * @par Example
947 *
948 * Here is an example of how to use this class:
949 * \code{.cc}
950 * double mean = 5.0;
951 * double variance = 2.0;
952 *
953 * Ptr<NormalRandomVariable> x = CreateObject<NormalRandomVariable> ();
954 * x->SetAttribute ("Mean", DoubleValue (mean));
955 * x->SetAttribute ("Variance", DoubleValue (variance));
956 *
957 * // The expected value for the mean of the values returned by a
958 * // normally distributed random variable is equal to mean.
959 * double value = x->GetValue ();
960 * @endcode
961 *
962 * @par Antithetic Values.
963 *
964 * If an instance of this RNG is configured to return antithetic values,
965 * the actual values returned, \f$x_1^{\prime}\f$ and \f$x_2^{\prime}\f$,
966 * are calculated as follows:
967 *
968 * \f{eqnarray*}{
969 * v_1^{\prime} & = & 2 (1 - u_1) - 1 \\
970 * v_2^{\prime} & = & 2 (1 - u_2) - 1 \\
971 * r^{\prime 2} & = & v_1^{\prime 2} + v_2^{\prime 2} \\
972 * y^{\prime} & = & \sqrt{\frac{-2 \log(r^{\prime 2})}{r^{\prime 2}}} \\
973 * x_1^{\prime} & = & \mu + v_1^{\prime} y^{\prime} \sqrt{\sigma^2} \\
974 * x_2^{\prime} & = & \mu + v_2^{\prime} y^{\prime} \sqrt{\sigma^2} ,
975 * \f}
976 *
977 * which now involves the distances \f$u_1\f$ and \f$u_2\f$ are from 1.
978 */
980{
981 public:
982 /// Large constant to bound the range.
983 static constexpr double INFINITE_VALUE = std::numeric_limits<double>::max();
984
985 /**
986 * @brief Register this type.
987 * @return The object TypeId.
988 */
989 static TypeId GetTypeId();
990
991 /**
992 * @brief Creates a normal distribution RNG with the default
993 * values for the mean, variance, and bound.
994 */
996
997 /**
998 * @brief Returns the mean value for the normal distribution returned by this RNG stream.
999 * @return The mean value for the normal distribution returned by this RNG stream.
1000 */
1001 double GetMean() const;
1002
1003 /**
1004 * @brief Returns the variance value for the normal distribution returned by this RNG stream.
1005 * @return The variance value for the normal distribution returned by this RNG stream.
1006 */
1007 double GetVariance() const;
1008
1009 /**
1010 * @brief Returns the standard deviation value for the normal distribution returned by this RNG
1011 * stream.
1012 * @return The standard deviation value for the normal distribution returned by this RNG stream.
1013 */
1014 double GetStdDev() const;
1015
1016 /**
1017 * @brief Returns the bound on values that can be returned by this RNG stream.
1018 * @return The bound on values that can be returned by this RNG stream.
1019 */
1020 double GetBound() const;
1021
1022 /**
1023 * @copydoc GetValue()
1024 * @param [in] mean Mean value for the normal distribution.
1025 * @param [in] variance Variance value for the normal distribution.
1026 * @param [in] bound Bound on values returned.
1027 */
1028 double GetValue(double mean,
1029 double variance,
1031
1032 /** @copydoc GetValue(double,double,double) */
1033 uint32_t GetInteger(uint32_t mean, uint32_t variance, uint32_t bound);
1034
1035 /**
1036 * Set standard deviation of this normal distribution RNG stream.
1037 * The deviation is squared and stored as variance, which can also be set
1038 * via the variance attribute.
1039 * @param [in] stdDev Standard deviation value for the normal distribution.
1040 */
1041 void SetStdDev(double stdDev);
1042
1043 // Inherited
1044 double GetValue() override;
1046
1047 private:
1048 /** The mean value for the normal distribution returned by this RNG stream. */
1049 double m_mean;
1050
1051 /** The variance value for the normal distribution returned by this RNG stream. */
1053
1054 /** The bound on values that can be returned by this RNG stream. */
1055 double m_bound;
1056
1057 /** True if the next value is valid. */
1059
1060 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1061 double m_v2;
1062 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1063 double m_y;
1064
1065 // end of class NormalRandomVariable
1066};
1067
1068/**
1069 * @ingroup randomvariable
1070 * @brief The log-normal distribution Random Number Generator
1071 * (RNG) that allows stream numbers to be set deterministically.
1072 *
1073 * This class supports the creation of objects that return random
1074 * numbers from a fixed log-normal distribution. It also supports the
1075 * generation of single random numbers from various log-normal
1076 * distributions. If one takes the natural logarithm of a random
1077 * variable following the log-normal distribution, the obtained values
1078 * follow a normal distribution.
1079 *
1080 * The probability density function is defined using two parameters
1081 * \c Mu = \f$\mu\f$ and \c Sigma = \f$\sigma\f$ as:
1082 *
1083 * \f[
1084 * P(x; \mu, \sigma) dx = \frac{1}{x\sqrt{2\pi\sigma^2}}
1085 * e^{-\frac{(ln(x) - \mu)^2}{2\sigma^2}} dx, \\
1086 * \quad x \in [0, +\infty)
1087 * \f]
1088 *
1089 * The distribution has mean value
1090 *
1091 * \f[
1092 * \langle x | P(x; \mu, \sigma) \rangle = e^{\mu+\frac{\sigma^2}{2}}
1093 * \f]
1094 *
1095 * and variance
1096 *
1097 * \f[
1098 * var(x) = (e^{\sigma^2}-1)e^{2\mu+\sigma^2}
1099 * \f]
1100 *
1101 * Note these are the mean and variance of the log-normal distribution,
1102 * not the \c Mu or \c Sigma configuration variables.
1103 *
1104 * If the desired mean and variance are known the \f$\mu\f$ and \f$\sigma\f$
1105 * parameters can be calculated instead with the following equations:
1106 *
1107 * \f[
1108 * \mu = ln(\langle x \rangle) - \\
1109 * \frac{1}{2}ln\left(1+\frac{var(x)}{{\langle x \rangle}^2}\right)
1110 * \f]
1111 *
1112 * and
1113 *
1114 * \f[
1115 * \sigma^2 = ln\left(1+\frac{var(x)}{{\langle x \rangle}^2}\right)
1116 * \f]
1117 *
1118 * If \f$u_1\f$, \f$u_2\f$ are uniform variables over [0,1]
1119 * then the log-normal RNG value, \f$x\f$ is generated as follows:
1120 *
1121 * \f{eqnarray*}{
1122 * v_1 & = & 2 u_1 - 1 \\
1123 * v_2 & = & 2 u_2 - 1 \\
1124 * r^2 & = & v_1^2 + v_2^2 \\
1125 * y & = & \sqrt{\frac{-2 \log{r^2}}{r^2}} \\
1126 * x & = & \exp\left(\mu + v_1 y \sigma\right) .
1127 * \f}
1128 *
1129 * @par Example
1130 *
1131 * Here is an example of how to use this class:
1132 * \code{.cc}
1133 * double mu = 5.0;
1134 * double sigma = 2.0;
1135 *
1136 * Ptr<LogNormalRandomVariable> x = CreateObject<LogNormalRandomVariable> ();
1137 * x->SetAttribute ("Mu", DoubleValue (mu));
1138 * x->SetAttribute ("Sigma", DoubleValue (sigma));
1139 *
1140 * double value = x->GetValue ();
1141 * @endcode
1142 *
1143 * @par Antithetic Values.
1144 *
1145 * If an instance of this RNG is configured to return antithetic values,
1146 * the actual value returned, \f$x'\f$, is generated as follows:
1147 *
1148 * \f{eqnarray*}{
1149 * v_1^{\prime} & = & 2 (1 - u_1) - 1 \\
1150 * v_2^{\prime} & = & 2 (1 - u_2) - 1 \\
1151 * r^{\prime 2} & = & v_1^{\prime 2} + v_2^{\prime 2} \\
1152 * y^{\prime} & = & v_1^{\prime}\sqrt{\frac{-2 \log(r^{\prime 2})}{r^{\prime 2}}} \\
1153 * x^{\prime} & = & \exp\left(\mu + y^{\prime} \sigma\right) .
1154 * \f}
1155 *
1156 * which now involves the distances \f$u_1\f$ and \f$u_2\f$ are from 1.
1157 */
1159{
1160 public:
1161 /**
1162 * @brief Register this type.
1163 * @return The object TypeId.
1164 */
1165 static TypeId GetTypeId();
1166
1167 /**
1168 * @brief Creates a log-normal distribution RNG with the default
1169 * values for mu and sigma.
1170 */
1172
1173 /**
1174 * @brief Returns the mu value for the log-normal distribution returned by this RNG stream.
1175 * @return The mu value for the log-normal distribution returned by this RNG stream.
1176 */
1177 double GetMu() const;
1178
1179 /**
1180 * @brief Returns the sigma value for the log-normal distribution returned by this RNG stream.
1181 * @return The sigma value for the log-normal distribution returned by this RNG stream.
1182 */
1183 double GetSigma() const;
1184
1185 /**
1186 * @copydoc GetValue()
1187 * @param [in] mu Mu value for the log-normal distribution.
1188 * @param [in] sigma Sigma value for the log-normal distribution.
1189 */
1190 double GetValue(double mu, double sigma);
1191
1192 /** @copydoc GetValue(double,double) */
1194
1195 // Inherited
1196 double GetValue() override;
1198
1199 private:
1200 /** The mu value for the log-normal distribution returned by this RNG stream. */
1201 double m_mu;
1202
1203 /** The sigma value for the log-normal distribution returned by this RNG stream. */
1204 double m_sigma;
1205
1206 /** True if m_normal is valid. */
1208
1209 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1210 double m_v2;
1211
1212 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1213 double m_normal;
1214
1215 // end of class LogNormalRandomVariable
1216};
1217
1218/**
1219 * @ingroup randomvariable
1220 * @brief The gamma distribution Random Number Generator (RNG) that
1221 * allows stream numbers to be set deterministically.
1222 *
1223 * This class supports the creation of objects that return random numbers
1224 * from a fixed gamma distribution. It also supports the generation of
1225 * single random numbers from various gamma distributions.
1226 *
1227 * The probability distribution is defined in terms two parameters,
1228 * \c Alpha = \f$\alpha > 0\f$ and \c Beta = \f$ \beta > 0\f$.
1229 * (Note the Wikipedia entry for the
1230 * [Gamma Distribution](https://en.wikipedia.org/wiki/Gamma_distribution)
1231 * uses either the parameters \f$k, \theta\f$ or \f$\alpha, \beta\f$.
1232 * The parameters used here \f$(\alpha, \beta)_{\mbox{ns-3}}\f$ correspond to
1233 * \f$(\alpha, \frac{1}{\beta})_{\mbox{Wikipedia}}\f$.)
1234 *
1235 * The probability density function is:
1236 *
1237 * \f[
1238 * P(x; \alpha, \beta) dx = x^{\alpha-1} \\
1239 * \frac{e^{-\frac{x}{\beta}}}{\beta^\alpha \Gamma(\alpha)} dx, \\
1240 * \quad x \in [0, +\infty)
1241 * \f]
1242 *
1243 * where the mean is \f$ \mu = \alpha\beta \f$ and the variance is
1244 * \f$ \sigma^2 = \alpha \beta^2\f$.
1245 *
1246 * While gamma RNG values can be generated by an algorithm similar to
1247 * normal RNGs, the implementation used here is based on the paper
1248 * G. Marsaglia and W. W. Tsang,
1249 * [A simple method for generating Gamma variables](https://dl.acm.org/doi/10.1145/358407.358414),
1250 * ACM Transactions on Mathematical Software, Vol. 26, No. 3, Sept. 2000.
1251 *
1252 * @par Example
1253 *
1254 * Here is an example of how to use this class:
1255 * \code{.cc}
1256 * double alpha = 5.0;
1257 * double beta = 2.0;
1258 *
1259 * Ptr<GammaRandomVariable> x = CreateObject<GammaRandomVariable> ();
1260 * x->SetAttribute ("Alpha", DoubleValue (alpha));
1261 * x->SetAttribute ("Beta", DoubleValue (beta));
1262 *
1263 * double value = x->GetValue ();
1264 * @endcode
1265 *
1266 * @par Antithetic Values.
1267 *
1268 * If an instance of this RNG is configured to return antithetic values,
1269 * the actual value returned, \f$x'\f$, is generated using the prescription
1270 * in the Marsaglia, _et al_. paper cited above.
1271 */
1273{
1274 public:
1275 /**
1276 * @brief Register this type.
1277 * @return The object TypeId.
1278 */
1279 static TypeId GetTypeId();
1280
1281 /**
1282 * @brief Creates a gamma distribution RNG with the default values
1283 * for alpha and beta.
1284 */
1286
1287 /**
1288 * @brief Returns the alpha value for the gamma distribution returned by this RNG stream.
1289 * @return The alpha value for the gamma distribution returned by this RNG stream.
1290 */
1291 double GetAlpha() const;
1292
1293 /**
1294 * @brief Returns the beta value for the gamma distribution returned by this RNG stream.
1295 * @return The beta value for the gamma distribution returned by this RNG stream.
1296 */
1297 double GetBeta() const;
1298
1299 /**
1300 * @copydoc GetValue()
1301 * @param [in] alpha Alpha value for the gamma distribution.
1302 * @param [in] beta Beta value for the gamma distribution.
1303 */
1304 double GetValue(double alpha, double beta);
1305
1306 /** @copydoc GetValue(double,double) */
1308
1309 // Inherited
1310 double GetValue() override;
1312
1313 private:
1314 /**
1315 * @brief Returns a random double from a normal distribution with the specified mean, variance,
1316 * and bound.
1317 * @param [in] mean Mean value for the normal distribution.
1318 * @param [in] variance Variance value for the normal distribution.
1319 * @param [in] bound Bound on values returned.
1320 * @return A floating point random value.
1321 */
1322 double GetNormalValue(double mean, double variance, double bound);
1323
1324 /** The alpha value for the gamma distribution returned by this RNG stream. */
1325 double m_alpha;
1326
1327 /** The beta value for the gamma distribution returned by this RNG stream. */
1328 double m_beta;
1329
1330 /** True if the next normal value is valid. */
1332
1333 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1334 double m_v2;
1335 /** The algorithm produces two values at a time. Cache parameters for possible reuse.*/
1336 double m_y;
1337
1338 // end of class GammaRandomVariable
1339};
1340
1341/**
1342 * @ingroup randomvariable
1343 * @brief The Erlang distribution Random Number Generator (RNG) that
1344 * allows stream numbers to be set deterministically.
1345 *
1346 * This class supports the creation of objects that return random numbers
1347 * from a fixed Erlang distribution. It also supports the generation of
1348 * single random numbers from various Erlang distributions.
1349 *
1350 * The Erlang distribution is a special case of the Gamma distribution
1351 * where \f$k = \alpha > 0 \f$ is a positive definite integer.
1352 * Erlang distributed variables can be generated using a much faster
1353 * algorithm than Gamma variables.
1354 *
1355 * The probability distribution is defined in terms two parameters,
1356 * the \c K or shape parameter \f$ \in {1,2 \dots} \f$, and
1357 * the \c Lambda or scale parameter \f$ \in (0,1] \f$.
1358 * (Note the Wikipedia entry for the
1359 * [Erlang Distribution](https://en.wikipedia.org/wiki/Erlang_distribution)
1360 * uses the parameters \f$(k, \lambda)\f$ or \f$(k, \beta)\f$.
1361 * The parameters used here \f$(k, \lambda)_{\mbox{ns-3}}\f$ correspond to
1362 * \f$(k, \frac{1}{\lambda} = \beta)_{\mbox{Wikipedia}}\f$.)
1363 *
1364 * The probability density function is:
1365 *
1366 * \f[
1367 * P(x; k, \lambda) dx = \lambda^k \\
1368 * \frac{x^{k-1} e^{-\frac{x}{\lambda}}}{(k-1)!} dx, \\
1369 * \quad x \in [0, +\infty)
1370 * \f]
1371 *
1372 * with mean \f$ \mu = k \lambda \f$ and variance \f$ \sigma^2 = k \lambda^2 \f$.
1373 *
1374 * The Erlang RNG value \f$x\f$ is generated by
1375 *
1376 * \f[
1377 * x = - \lambda \sum_{i = 1}^{k}{\ln u_i}
1378 * \f]
1379 *
1380 * where the \f$u_i\f$ are \f$k\f$ uniform random variables on [0,1).
1381 *
1382 * @par Example
1383 *
1384 * Here is an example of how to use this class:
1385 * \code{.cc}
1386 * uint32_t k = 5;
1387 * double lambda = 2.0;
1388 *
1389 * Ptr<ErlangRandomVariable> x = CreateObject<ErlangRandomVariable> ();
1390 * x->SetAttribute ("K", IntegerValue (k));
1391 * x->SetAttribute ("Lambda", DoubleValue (lambda));
1392 *
1393 * double value = x->GetValue ();
1394 * @endcode
1395 *
1396 * @par Antithetic Values.
1397 *
1398 * If an instance of this RNG is configured to return antithetic values,
1399 * the actual value returned, \f$x'\f$, is generated as follows:
1400 *
1401 * \f[
1402 * x' = - \lambda \sum_{i = 1}^{k}{\ln (1 - u_i)}
1403 * \f]
1404 *
1405 * which now involves the log of the distance \f$u\f$ is from 1.
1406 */
1408{
1409 public:
1410 /**
1411 * @brief Register this type.
1412 * @return The object TypeId.
1413 */
1414 static TypeId GetTypeId();
1415
1416 /**
1417 * @brief Creates an Erlang distribution RNG with the default values
1418 * for k and lambda.
1419 */
1421
1422 /**
1423 * @brief Returns the k value for the Erlang distribution returned by this RNG stream.
1424 * @return The k value for the Erlang distribution returned by this RNG stream.
1425 */
1426 uint32_t GetK() const;
1427
1428 /**
1429 * @brief Returns the lambda value for the Erlang distribution returned by this RNG stream.
1430 * @return The lambda value for the Erlang distribution returned by this RNG stream.
1431 */
1432 double GetLambda() const;
1433
1434 /**
1435 * @copydoc GetValue()
1436 * @param [in] k K value for the Erlang distribution.
1437 * @param [in] lambda Lambda value for the Erlang distribution.
1438 */
1439 double GetValue(uint32_t k, double lambda);
1440
1441 /** @copydoc GetValue(uint32_t,double) */
1443
1444 // Inherited
1445 double GetValue() override;
1447
1448 private:
1449 /**
1450 * @brief Returns a random double from an exponential distribution with the specified mean and
1451 * upper bound.
1452 * @param [in] mean Mean value of the random variables.
1453 * @param [in] bound Upper bound on values returned.
1454 * @return A floating point random value.
1455 */
1456 double GetExponentialValue(double mean, double bound);
1457
1458 /** The k value for the Erlang distribution returned by this RNG stream. */
1460
1461 /** The lambda value for the Erlang distribution returned by this RNG stream. */
1462 double m_lambda;
1463
1464 // end of class ErlangRandomVariable
1465};
1466
1467/**
1468 * @ingroup randomvariable
1469 * @brief The triangular distribution Random Number Generator (RNG) that
1470 * allows stream numbers to be set deterministically.
1471 *
1472 * This class supports the creation of objects that return random numbers
1473 * from a fixed triangular distribution. It also supports the generation of
1474 * single random numbers from various triangular distributions.
1475 *
1476 * The probability density depends on three parameters, the end points
1477 * \f$a\f$ = \c Min and \f$b\f$ = \c Max, and the location of the peak or mode,
1478 * \f$c\f$. For historical reasons this formulation uses the \c Mean,
1479 * \f$\mu = \frac{(a + b + c)}{3}\f$ instead of the mode.
1480 * In terms of the \c Mean, the mode is \f$c = 3 \mu - a - b\f$.
1481 *
1482 * The probability is in the shape of a triangle defined on the interval
1483 * \f$ x \in [a, b] \f$:
1484 *
1485 * \f[
1486 * P(x; a, b, c) dx = \begin{array}{ll}
1487 * 0 &\mbox{ for $x \le a$} \\
1488 * \frac{2(x - a)}{(b - a)(c - a)} dx &\mbox{ for $a \le x \le c$} \\
1489 * \frac{2}{b - 1} dx &\mbox{ for $x = c$} \\
1490 * \frac{2(b - x)}{(b - a)(b - c)} dx &\mbox{ for $c \le x \le b$} \\
1491 * 0 &\mbox{ for $b \le x$}
1492 * \end{array}
1493 * \f]
1494 *
1495 * The triangle RNG \f$x\f$ is generated by
1496 *
1497 * \f[
1498 * x = \left\{ \begin{array}{rl}
1499 * a + \sqrt{u (b - a) (c - a)} &\mbox{ if $u \le (c - a)/(b - a)$} \\
1500 * b - \sqrt{(1 - u) (b - a) (b - c) } &\mbox{ otherwise}
1501 * \end{array}
1502 * \right.
1503 * \f]
1504 *
1505 * where \f$u\f$ is a uniform random variable on [0,1).
1506 *
1507 * @par Example
1508 *
1509 * Here is an example of how to use this class:
1510 * \code{.cc}
1511 * double mean = 5.0;
1512 * double min = 2.0;
1513 * double max = 10.0;
1514 *
1515 * Ptr<TriangularRandomVariable> x = CreateObject<TriangularRandomVariable> ();
1516 * x->SetAttribute ("Mean", DoubleValue (mean));
1517 * x->SetAttribute ("Min", DoubleValue (min));
1518 * x->SetAttribute ("Max", DoubleValue (max));
1519 *
1520 * double value = x->GetValue ();
1521 * @endcode
1522 *
1523 * @par Antithetic Values.
1524 *
1525 * If an instance of this RNG is configured to return antithetic values,
1526 * the actual value returned, \f$x'\f$, is generated as follows:
1527 *
1528 * \f[
1529 * x = \left\{ \begin{array}{rl}
1530 * a + \sqrt{(1 - u) (b - a) (c - a)} &\mbox{ if $(1 - u) \le (c - a)/(b - a)$} \\
1531 * b - \sqrt{u (b - a) (b - c) } &\mbox{ otherwise}
1532 * \end{array}
1533 * \right.
1534 * \f]
1535 *
1536 * which now involves the distance \f$u\f$ is from 1.
1537 */
1539{
1540 public:
1541 /**
1542 * @brief Register this type.
1543 * @return The object TypeId.
1544 */
1545 static TypeId GetTypeId();
1546
1547 /**
1548 * @brief Creates a triangular distribution RNG with the default
1549 * values for the mean, lower bound, and upper bound.
1550 */
1552
1553 /**
1554 * @brief Returns the mean value for the triangular distribution returned by this RNG stream.
1555 * @return The mean value for the triangular distribution returned by this RNG stream.
1556 */
1557 double GetMean() const;
1558
1559 /**
1560 * @brief Returns the lower bound for the triangular distribution returned by this RNG stream.
1561 * @return The lower bound for the triangular distribution returned by this RNG stream.
1562 */
1563 double GetMin() const;
1564
1565 /**
1566 * @brief Returns the upper bound on values that can be returned by this RNG stream.
1567 * @return The upper bound on values that can be returned by this RNG stream.
1568 */
1569 double GetMax() const;
1570
1571 /**
1572 * @copydoc GetValue()
1573 * @param [in] mean Mean value for the triangular distribution.
1574 * @param [in] min Low end of the range.
1575 * @param [in] max High end of the range.
1576 */
1577 double GetValue(double mean, double min, double max);
1578
1579 /** @copydoc GetValue(double,double,double) */
1581
1582 // Inherited
1583 double GetValue() override;
1585
1586 private:
1587 /** The mean value for the triangular distribution returned by this RNG stream. */
1588 double m_mean;
1589
1590 /** The lower bound on values that can be returned by this RNG stream. */
1591 double m_min;
1592
1593 /** The upper bound on values that can be returned by this RNG stream. */
1594 double m_max;
1595
1596 // end of class TriangularRandomVariable
1597};
1598
1599/**
1600 * @ingroup randomvariable
1601 * @brief The Zipf distribution Random Number Generator (RNG) that
1602 * allows stream numbers to be set deterministically.
1603 *
1604 * This class supports the creation of objects that return random numbers
1605 * from a fixed Zipf distribution. It also supports the generation of
1606 * single random numbers from various Zipf distributions.
1607 *
1608 * Zipf's law states that given some corpus of natural language
1609 * utterances, the frequency of any word is inversely proportional
1610 * to its rank in the frequency table.
1611 *
1612 * Zipf's distribution has two parameters, \c Alpha and \c N, where:
1613 * \f$ \alpha \ge 0 \f$ (real) and \f$ N \in \{1,2,3 \dots\} \f$ (integer).
1614 * (Note the Wikipedia entry for the
1615 * [Zipf Distribution](https://en.wikipedia.org/wiki/Zipf%27s_law)
1616 * uses the symbol \f$s\f$ instead of \f$\alpha\f$.)
1617 *
1618 * The probability mass function is:
1619 *
1620 * \f[
1621 * P(k; \alpha, N) = \frac{1}{k^\alpha H_{N,\alpha}}
1622 * \f]
1623 *
1624 * where the \c N-th generalized harmonic number is
1625 *
1626 * \f[
1627 * H_{N,\alpha} = \sum_{m=1}^N \frac{1}{m^\alpha}
1628 * \f]
1629 *
1630 * Note the Zipf distribution is a discrete distribution, so the
1631 * returned values \f$k\f$ will always be integers in the range \f$k
1632 * \in {1,2 \dots N} \f$.
1633 *
1634 * The mean of the distribution is
1635 *
1636 * \f[
1637 * \mu = \frac{H_{N,\alpha - 1}}{H_{N,\alpha}}
1638 * \f]
1639 *
1640 * The Zipf RNG value \f$k\f$ is the smallest value such that
1641 *
1642 * \f[
1643 * u < \frac{H_k,\alpha}{H_N,\alpha}
1644 * \f]
1645 *
1646 * where \f$u\f$ is a uniform random variable on [0,1).
1647 *
1648 * @par Example
1649 *
1650 * Here is an example of how to use this class:
1651 * \code{.cc}
1652 * uint32_t n = 1;
1653 * double alpha = 2.0;
1654 *
1655 * Ptr<ZipfRandomVariable> x = CreateObject<ZipfRandomVariable> ();
1656 * x->SetAttribute ("N", IntegerValue (n));
1657 * x->SetAttribute ("Alpha", DoubleValue (alpha));
1658 *
1659 * double value = x->GetValue ();
1660 * @endcode
1661 *
1662 * @par Antithetic Values.
1663 *
1664 * If an instance of this RNG is configured to return antithetic values,
1665 * the actual value returned, \f$k'\f$, is the value such that
1666 *
1667 * \f[
1668 * 1 - u < \frac{H_{k'},\alpha}{H_N,\alpha}
1669 * \f]
1670 *
1671 */
1673{
1674 public:
1675 /**
1676 * @brief Register this type.
1677 * @return The object TypeId.
1678 */
1679 static TypeId GetTypeId();
1680
1681 /**
1682 * @brief Creates a Zipf distribution RNG with the default values
1683 * for n and alpha.
1684 */
1686
1687 /**
1688 * @brief Returns the n value for the Zipf distribution returned by this RNG stream.
1689 * @return The n value for the Zipf distribution returned by this RNG stream.
1690 */
1691 uint32_t GetN() const;
1692
1693 /**
1694 * @brief Returns the alpha value for the Zipf distribution returned by this RNG stream.
1695 * @return The alpha value for the Zipf distribution returned by this RNG stream.
1696 */
1697 double GetAlpha() const;
1698
1699 /**
1700 * @copydoc GetValue()
1701 * @param [in] n N value for the Zipf distribution.
1702 * @param [in] alpha Alpha value for the Zipf distribution.
1703 * @return A floating point random value.
1704 */
1705 double GetValue(uint32_t n, double alpha);
1706
1707 /** @copydoc GetValue(uint32_t,double) */
1709
1710 // Inherited
1711 double GetValue() override;
1713
1714 private:
1715 /** The n value for the Zipf distribution returned by this RNG stream. */
1717
1718 /** The alpha value for the Zipf distribution returned by this RNG stream. */
1719 double m_alpha;
1720
1721 /** The normalization constant. */
1722 double m_c;
1723
1724 // end of class ZipfRandomVariable
1725};
1726
1727/**
1728 * @ingroup randomvariable
1729 * @brief The zeta distribution Random Number Generator (RNG) that
1730 * allows stream numbers to be set deterministically.
1731 *
1732 * This class supports the creation of objects that return random numbers
1733 * from a fixed zeta distribution. It also supports the generation of
1734 * single random numbers from various zeta distributions.
1735 *
1736 * The Zeta distribution is related to Zipf distribution by letting
1737 * \f$N \rightarrow \infty\f$.
1738 *
1739 * Zeta distribution has one parameter, \c Alpha, \f$ \alpha > 1 \f$ (real).
1740 * (Note the Wikipedia entry for the
1741 * [Zeta Distribution](https://en.wikipedia.org/wiki/Zeta_distribution)
1742 * uses the symbol \f$s\f$ instead of \f$\alpha\f$.)
1743 * The probability mass Function is
1744 *
1745 * \f[
1746 * P(k; \alpha) = k^{-\alpha}/\zeta(\alpha)
1747 * \f]
1748 *
1749 * where \f$ \zeta(\alpha) \f$ is the Riemann zeta function
1750 *
1751 * \f[
1752 * \zeta(\alpha) = \sum_{n=1}^\infty \frac{1}{n^\alpha}
1753 * \f]
1754 *
1755 * Note the Zeta distribution is a discrete distribution, so the
1756 * returned values \f$k\f$ will always be integers in the range
1757 * \f$k \in {1,2 \dots} \f$.
1758 *
1759 * The mean value of the distribution is
1760 *
1761 * \f[
1762 * \mu = \frac{\zeta(\alpha - 1)}{\zeta(\alpha)}, \quad \alpha > 2
1763 * \f]
1764 *
1765 * The Zeta RNG \f$x\f$ is generated by an accept-reject algorithm;
1766 * see the implementation of GetValue(double).
1767 *
1768 * @par Example
1769 *
1770 * Here is an example of how to use this class:
1771 * \code{.cc}
1772 * double alpha = 2.0;
1773 *
1774 * Ptr<ZetaRandomVariable> x = CreateObject<ZetaRandomVariable> ();
1775 * x->SetAttribute ("Alpha", DoubleValue (alpha));
1776 *
1777 * double value = x->GetValue ();
1778 * @endcode
1779 *
1780 * @par Antithetic Values.
1781 *
1782 * If an instance of this RNG is configured to return antithetic values,
1783 * the actual value returned, \f$x'\f$, is generated by using
1784 * \f$ 1 - u \f$ instead. of \f$u\f$ on [0, 1].
1785 */
1787{
1788 public:
1789 /**
1790 * @brief Register this type.
1791 * @return The object TypeId.
1792 */
1793 static TypeId GetTypeId();
1794
1795 /**
1796 * @brief Creates a zeta distribution RNG with the default value for
1797 * alpha.
1798 */
1800
1801 /**
1802 * @brief Returns the alpha value for the zeta distribution returned by this RNG stream.
1803 * @return The alpha value for the zeta distribution returned by this RNG stream.
1804 */
1805 double GetAlpha() const;
1806
1807 /**
1808 * @copydoc GetValue()
1809 * @param [in] alpha Alpha value for the zeta distribution.
1810 */
1811 double GetValue(double alpha);
1812
1813 /** @copydoc GetValue(double) */
1815
1816 // Inherited
1817 double GetValue() override;
1819
1820 private:
1821 /** The alpha value for the zeta distribution returned by this RNG stream. */
1822 double m_alpha;
1823
1824 /** Just for calculus simplifications. */
1825 double m_b;
1826
1827 // end of class ZetaRandomVariable
1828};
1829
1830/**
1831 * @ingroup randomvariable
1832 * @brief The Random Number Generator (RNG) that returns a predetermined sequence.
1833 *
1834 * Defines a random variable that has a specified, predetermined
1835 * sequence. This would be useful when trying to force the RNG to
1836 * return a known sequence, perhaps to compare ns-3 to some other
1837 * simulator
1838 *
1839 * Creates a generator that returns successive elements from the value
1840 * array on successive calls to GetValue(). Note
1841 * that the values in the array are copied and stored by the generator
1842 * (deep-copy). Also note that the sequence repeats if more values
1843 * are requested than are present in the array.
1844 *
1845 * @par Example
1846 *
1847 * Here is an example of how to use this class:
1848 * \code{.cc}
1849 * Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable> ();
1850 *
1851 * std::vector array{ 4, 4, 7, 7, 10, 10};
1852 * s->SetValueArray (array);
1853 *
1854 * double value = x->GetValue ();
1855 * @endcode
1856 *
1857 * This will return values in the repeating sequence
1858 *
1859 * \f[
1860 * x \in 4, 4, 7, 7, 10, 10, 4, \dots
1861 * \f]
1862 *
1863 * @par Antithetic Values.
1864 *
1865 * This RNG ignores the antithetic setting.
1866 */
1868{
1869 public:
1870 /**
1871 * @brief Register this type.
1872 * @return The object TypeId.
1873 */
1874 static TypeId GetTypeId();
1875
1876 /**
1877 * @brief Creates a deterministic RNG that will have a predetermined
1878 * sequence of values.
1879 */
1882
1883 /**
1884 * @brief Sets the array of values that holds the predetermined sequence.
1885 *
1886 * Note that the values in the array are copied and stored
1887 * (deep-copy).
1888 * @param [in] values Array of random values to return in sequence.
1889 */
1890 void SetValueArray(const std::vector<double>& values);
1891 /**
1892 * @brief Sets the array of values that holds the predetermined sequence.
1893 *
1894 * Note that the values in the array are copied and stored
1895 * (deep-copy).
1896 * @param [in] values Array of random values to return in sequence.
1897 * @param [in] length Number of values in the array.
1898 */
1899 void SetValueArray(const double* values, std::size_t length);
1900
1901 // Inherited
1902 double GetValue() override;
1904
1905 private:
1906 /** Size of the array of values. */
1907 std::size_t m_count;
1908
1909 /** Position of the next value in the array of values. */
1910 std::size_t m_next;
1911
1912 /** Array of values to return in sequence. */
1913 double* m_data;
1914
1915 // end of class DeterministicRandomVariable
1916};
1917
1918/**
1919 * @ingroup randomvariable
1920 * @brief The Random Number Generator (RNG) that has a specified
1921 * empirical distribution.
1922 *
1923 * Defines a random variable that has a specified, empirical
1924 * distribution. The cumulative probability distribution function
1925 * (CDF) is specified by a series of calls to the CDF() member
1926 * function, specifying a value \f$x\f$ and the probability \f$P(x)\f$
1927 * that the distribution is less than the specified value. When
1928 * random values are requested, a uniform random variable
1929 * \f$ u \in [0, 1] \f$ is used to select a probability,
1930 * and the return value is chosen as the largest input value
1931 * with CDF less than the random value. This method is known as
1932 * [inverse transform sampling](http://en.wikipedia.org/wiki/Inverse_transform_sampling).
1933 *
1934 * This generator has two modes: *sampling* and *interpolating*.
1935 * In *sampling* mode this random variable generator
1936 * treats the CDF as an exact histogram and returns
1937 * one of the histogram inputs exactly. This is appropriate
1938 * when the configured CDF represents the exact probability
1939 * distribution, for a categorical variable, for example.
1940 *
1941 * In *interpolating* mode this random variable generator linearly
1942 * interpolates between the CDF values defining the histogram bins.
1943 * This is appropriate when the configured CDF is an approximation
1944 * to a continuous underlying probability distribution.
1945 *
1946 * For historical reasons the default is sampling. To switch modes
1947 * use the \c Interpolate Attribute, or call SetInterpolate(). You
1948 * can change modes at any time.
1949 *
1950 * If you find yourself switching frequently it could be simpler to
1951 * set the mode to sampling, then use the GetValue() function for
1952 * sampled values, and Interpolate() function for interpolated values.
1953 *
1954 * The CDF need not start with a probability of zero, nor end with a
1955 * probability of 1.0. If the selected uniform random value
1956 * \f$ u \in [0,1] \f$ is less than the probability of the first CDF point,
1957 * that point is selected. If \f$u\f$ is greater than the probability of
1958 * the last CDF point the last point is selected. In either case the
1959 * interpolating mode will *not* interpolate (since there is no value
1960 * beyond the first/last to work with), but simply return the extremal CDF
1961 * value, as in sampling.
1962 *
1963 * @par Example
1964 *
1965 * Here is an example of how to use this class:
1966 * \code{.cc}
1967 * // Create the RNG with a non-uniform distribution between 0 and 10.
1968 * // in sampling mode.
1969 * Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> ();
1970 * x->SetInterpolate (false);
1971 * x->CDF ( 0.0, 0.0);
1972 * x->CDF ( 5.0, 0.25);
1973 * x->CDF (10.0, 1.0);
1974 *
1975 * double value = x->GetValue ();
1976 * @endcode
1977 *
1978 * The expected values and probabilities returned by GetValue() are
1979 *
1980 * Value | Probability
1981 * ----: | ----------:
1982 * 0.0 | 0
1983 * 5.0 | 25%
1984 * 10.0 | 75%
1985 *
1986 * The only two values ever returned are 5 and 10, in the ratio 1:3.
1987 *
1988 * If instead you want linear interpolation between the points of the CDF
1989 * use the Interpolate() function:
1990 *
1991 * double interp = x->Interpolate ();
1992 *
1993 * This will return continuous values on the range [0,1), 25% of the time
1994 * less than 5, and 75% of the time between 5 and 10.
1995 *
1996 * See empirical-random-variable-example.cc for an example.
1997 *
1998 * @par Antithetic Values.
1999 *
2000 * If an instance of this RNG is configured to return antithetic values,
2001 * the actual value returned, \f$x'\f$, is generated by using
2002 * \f$ 1 - u \f$ instead. of \f$u\f$ on [0, 1].
2003 */
2005{
2006 public:
2007 /**
2008 * @brief Register this type.
2009 * @return The object TypeId.
2010 */
2011 static TypeId GetTypeId();
2012
2013 /**
2014 * @brief Creates an empirical RNG that has a specified, empirical
2015 * distribution, and configured for interpolating mode.
2016 */
2018
2019 /**
2020 * @brief Specifies a point in the empirical distribution
2021 *
2022 * @param [in] v The function value for this point
2023 * @param [in] c Probability that the function is less than or equal to \p v
2024 * In other words this is cumulative distribution function
2025 * at \p v.
2026 */
2027 void CDF(double v, double c); // Value, prob <= Value
2028
2029 // Inherited
2030 /**
2031 * @copydoc RandomVariableStream::GetValue()
2032 * @note This does not interpolate the CDF, but treats it as a
2033 * stepwise continuous function.
2034 */
2035 double GetValue() override;
2037
2038 /**
2039 * @brief Returns the next value in the empirical distribution using
2040 * linear interpolation.
2041 * @return The floating point next value in the empirical distribution
2042 * using linear interpolation.
2043 */
2044 virtual double Interpolate();
2045
2046 /**
2047 * @brief Switch the mode between sampling the CDF and interpolating.
2048 * The default mode is sampling.
2049 * @param [in] interpolate If \c true set to interpolation, otherwise sampling.
2050 * @returns The previous interpolate flag value.
2051 */
2052 bool SetInterpolate(bool interpolate);
2053
2054 private:
2055 /**
2056 * @brief Check that the CDF is valid.
2057 *
2058 * A valid CDF has
2059 *
2060 * - Strictly increasing arguments, and
2061 * - Strictly increasing CDF.
2062 *
2063 * It is a fatal error to fail validation.
2064 */
2065 void Validate();
2066 /**
2067 * @brief Do the initial rng draw and check against the extrema.
2068 *
2069 * If the extrema apply, \c value will have the extremal value
2070 * and the return will be \c true.
2071 *
2072 * If the extrema do not apply \c value will have the URNG value
2073 * and the return will be \c false.
2074 *
2075 * @param [out] value The extremal value, or the URNG.
2076 * @returns \c true if \p value is the extremal result,
2077 * or \c false if \p value is the URNG value.
2078 */
2079 bool PreSample(double& value);
2080 /**
2081 * @brief Sample the CDF as a histogram (without interpolation).
2082 * @param [in] r The CDF value at which to sample the CDF.
2083 * @return The bin value corresponding to \c r.
2084 */
2085 double DoSampleCDF(double r);
2086 /**
2087 * @brief Linear interpolation between two points on the CDF to estimate
2088 * the value at \p r.
2089 *
2090 * @param [in] r The argument value to interpolate to.
2091 * @returns The interpolated CDF at \pname{r}
2092 */
2093 double DoInterpolate(double r);
2094
2095 /** \c true once the CDF has been validated. */
2097 /**
2098 * The map of CDF points (x, F(x)).
2099 * The CDF points are stored in the std::map in reverse order, as follows:
2100 * Key: CDF F(x) [0, 1] | Value: domain value (x) [-inf, inf].
2101 */
2102 std::map<double, double> m_empCdf;
2103 /**
2104 * If \c true GetValue will interpolate,
2105 * otherwise treat CDF as normal histogram.
2106 */
2108
2109 // end of class EmpiricalRandomVariable
2110};
2111
2112/**
2113 * @ingroup randomvariable
2114 * @brief The binomial distribution Random Number Generator (RNG).
2115 *
2116 * This class supports the creation of objects that return random numbers
2117 * from a fixed binomial distribution. It also supports the generation of
2118 * single random numbers from various binomial distributions.
2119 *
2120 * The probability mass function of a binomial variable
2121 * is defined as:
2122 *
2123 * \f[
2124 * P(k; n, p) = \binom{n}{k} p^k (1-p)^{n-k}, \\
2125 * \quad k \in [0, n]
2126 * \f]
2127 *
2128 * where \f$ n \f$ is the number of trials and \f$ p \f$ is the probability
2129 * of success in each trial. The mean of this distribution
2130 * is \f$ \mu = np \f$ and the variance is \f$ \sigma^2 = np(1-p) \f$.
2131 *
2132 * The Binomial RNG value \f$n\f$ for a given number of trials \f$ n \f$
2133 * and success probability \f$ p \f$ is generated by
2134 *
2135 * \f[
2136 * k = \sum_{i=1}^{n} I(u_i \leq p)
2137 * \f]
2138 *
2139 * where \f$u_i\f$ is a uniform random variable on [0,1) for each trial,
2140 * and \f$I\f$ is an indicator function that is 1 if \f$u_i \leq p\f$ and 0 otherwise.
2141 * The sum of these indicator functions over all trials gives the total
2142 * number of successes, which is the value of the binomial random variable.
2143 *
2144 * @par Example
2145 *
2146 * Here is an example of how to use this class:
2147 * \code{.cc}
2148 * uint32_t trials = 10;
2149 * double probability = 0.5;
2150 *
2151 * Ptr<BinomialRandomVariable> x = CreateObject<BinomialRandomVariable> ();
2152 * x->SetAttribute ("Trials", UintegerValue (trials));
2153 * x->SetAttribute ("Probability", DoubleValue (probability));
2154 *
2155 * double successes = x->GetValue ();
2156 * @endcode
2157 *
2158 * @par Antithetic Values.
2159 *
2160 * If an instance of this RNG is configured to return antithetic values,
2161 * the actual value returned, \f$n'\f$, for the Binomial process is determined by:
2162 *
2163 * \f[
2164 * k' = \sum_{i=1}^{n} I((1 - u_i) \leq p)
2165 * \f]
2166 *
2167 * where \f$u_i\f$ is a uniform random variable on [0,1) for each trial.
2168 * The antithetic approach uses \f$(1 - u_i)\f$ instead of \f$u_i\f$ in the indicator function.
2169 *
2170 * @par Efficiency and Alternative Methods
2171 *
2172 * There are alternative methods for generating binomial distributions that may offer greater
2173 * efficiency. However, this implementation opts for a simpler approach. Although not as efficient,
2174 * this method was chosen for its simplicity and sufficiency in most applications.
2175 */
2177{
2178 public:
2179 /**
2180 * @brief Register this type.
2181 * @return The object TypeId.
2182 */
2183 static TypeId GetTypeId();
2184
2186
2187 /**
2188 * @copydoc GetValue()
2189 * @param [in] trials Number of trials.
2190 * @param [in] probability Probability of success in each trial.
2191 * @return Returns a number within the range [0, trials] indicating the number of successful
2192 * trials.
2193 */
2194 double GetValue(uint32_t trials, double probability);
2195
2196 /**
2197 * @copydoc GetValue(uint32_t,double)
2198 * This function is similar to GetValue(), but it returns a uint32_t instead of a double.
2199 */
2200 uint32_t GetInteger(uint32_t trials, uint32_t probability);
2201
2202 // Inherited
2203 double GetValue() override;
2205
2206 private:
2207 /** The number of trials. */
2209
2210 /** The probability of success in each trial. */
2212
2213 // end of class BinomialRandomVariable
2214};
2215
2216/**
2217 * @ingroup randomvariable
2218 * @brief The Bernoulli distribution Random Number Generator (RNG).
2219 *
2220 * This class supports the creation of objects that return random numbers
2221 * from a fixed Bernoulli distribution. It also supports the generation of
2222 * single random numbers from various Bernoulli distributions.
2223 *
2224 * The probability mass function of a Bernoulli variable
2225 * is defined as:
2226 *
2227 * \f[
2228 * P(n; p) = p^n (1-p)^{1-n}, \\
2229 * \quad n \in \{0, 1\}
2230 * \f]
2231 *
2232 * where \f$ p \f$ is the probability of success and n is the indicator of success, with n=1
2233 * representing success and n=0 representing failure. The mean of this distribution is \f$ \mu = p
2234 * \f$ and the variance is \f$ \sigma^2 = p(1-p) \f$.
2235 *
2236 * The Bernoulli RNG value \f$n\f$ is generated by
2237 *
2238 * \f[
2239 * n =
2240 * \begin{cases}
2241 * 1 & \text{if } u \leq p \\
2242 * 0 & \text{otherwise}
2243 * \end{cases}
2244 * \f]
2245 *
2246 * where \f$u\f$ is a uniform random variable on [0,1) and \f$p\f$ is the probability of success.
2247 *
2248 * @par Example
2249 *
2250 * Here is an example of how to use this class:
2251 * \code{.cc}
2252 * double probability = 0.5;
2253 *
2254 * Ptr<BernoulliRandomVariable> x = CreateObject<BernoulliRandomVariable> ();
2255 * x->SetAttribute ("Probability", DoubleValue (probability));
2256 *
2257 * double success = x->GetValue ();
2258 * @endcode
2259 *
2260 * @par Antithetic Values.
2261 *
2262 * If an instance of this RNG is configured to return antithetic values,
2263 * the actual value returned, \f$x'\f$, is determined by:
2264 *
2265 * \f[
2266 * x' =
2267 * \begin{cases}
2268 * 1 & \text{if } (1 - u) \leq p \\
2269 * 0 & \text{otherwise}
2270 * \end{cases}
2271 * \f]
2272 *
2273 * where \f$u\f$ is a uniform random variable on [0,1) and \f$p\f$ is the probability of success.
2274 */
2276{
2277 public:
2278 /**
2279 * @brief Register this type.
2280 * @return The object TypeId.
2281 */
2282 static TypeId GetTypeId();
2283
2285
2286 /**
2287 * @copydoc GetValue()
2288 * @param [in] probability Probability of success.
2289 * @return Returns 1 if the trial is successful, or 0 if it is not.
2290 */
2291 double GetValue(double probability);
2292
2293 /**
2294 * @copydoc GetValue(double)
2295 * This function is similar to GetValue(), but it returns a uint32_t instead of a double.
2296 */
2297 uint32_t GetInteger(uint32_t probability);
2298
2299 // Inherited
2300 double GetValue() override;
2302
2303 private:
2304 /** The probability of success. */
2306
2307 // end of class BernoulliRandomVariable
2308};
2309
2310/**
2311 * @ingroup randomvariable
2312 * @brief The laplacian distribution Random Number Generator (RNG).
2313 *
2314 * This class supports the creation of objects that return random numbers
2315 * from a fixed laplacian distribution.
2316 *
2317 * The probability density function of a laplacian variable
2318 * is defined as:
2319 *
2320 * \f[
2321 * P(x; \mu, \beta) dx = \frac{1}{2 \beta} e^{\frac{- \abs{x - \mu}}{\beta}} dx
2322 * \f]
2323 *
2324 * where \f$\mu\f$ is the \c Location configurable attribute and \f$\beta\f$
2325 * is the \c Scale configurable attribute. This distribution has mean \f$\mu\f$
2326 * and variance \f$ \sigma^2 = 2 \beta^2 \f$.
2327 *
2328 * The laplacian RNG value \f$x\f$ is generated by
2329 *
2330 * \f[
2331 * x = \mu - \beta sgn(u) \log(1 - 2 \abs{u})
2332 * \f]
2333 *
2334 * where \f$u\f$ is a uniform random variable on [-0.5,0.5).
2335 *
2336 * @par Bounded Distribution
2337 *
2338 * The Laplacian distribution can be bounded symmetrically about the mean by
2339 * the \c Bound parameter, \f$b\f$, _i.e._ its values are confined to the interval
2340 * \f$[\mu - b, \mu + b]\f$. This preserves the mean but decreases the variance.
2341 */
2343{
2344 public:
2345 /**
2346 * @brief Register this type.
2347 * @return The object TypeId.
2348 */
2349 static TypeId GetTypeId();
2350
2351 /**
2352 * @brief Creates an unbounded laplacian distribution RNG with the default
2353 * values for the location and the scale.
2354 */
2356
2357 /**
2358 * @brief Get the configured location value of this RNG.
2359 *
2360 * @return The configured location value.
2361 */
2362 double GetLocation() const;
2363
2364 /**
2365 * @brief Get the configured scale value of this RNG.
2366 *
2367 * @return The configured scale value.
2368 */
2369 double GetScale() const;
2370
2371 /**
2372 * @brief Get the configured bound of this RNG.
2373 * @return The bound.
2374 */
2375 double GetBound() const;
2376
2377 /**
2378 * @copydoc GetValue()
2379 * @param [in] location location value of the laplacian distribution.
2380 * @param [in] scale scale value of the laplacian distribution.
2381 * @param [in] bound bound on values returned.
2382 */
2383 double GetValue(double location, double scale, double bound);
2384
2385 /** @copydoc GetValue(double,double,double) */
2386 uint32_t GetInteger(uint32_t location, uint32_t scale, uint32_t bound);
2387
2388 // Inherited
2389 double GetValue() override;
2391
2392 /**
2393 * @brief Returns the variance value for the laplacian distribution returned by this RNG stream.
2394 * @return The variance value for the laplacian distribution returned by this RNG stream.
2395 */
2396 double GetVariance() const;
2397
2398 /**
2399 * @copydoc GetVariance()
2400 * @param [in] scale scale value of the laplacian distribution.
2401 */
2402 static double GetVariance(double scale);
2403
2404 private:
2405 /** The location value of the laplacian distribution. */
2407
2408 /** The scale value of the laplacian distribution. */
2409 double m_scale;
2410
2411 /** The bound on values that can be returned by this RNG stream. */
2412 double m_bound;
2413
2414 // end of class LaplacianRandomVariable
2415};
2416
2417/**
2418 * @ingroup randomvariable
2419 * @brief The Largest Extreme Value distribution Random Number Generator (RNG).
2420 *
2421 * This class supports the creation of objects that return random numbers from a fixed Largest
2422 * Extreme Value distribution. This corresponds to the type-I Generalized Extreme Value
2423 * distribution, also known as Gumbel distribution
2424 * (https://en.wikipedia.org/wiki/Gumbel_distribution).
2425 *
2426 * The probability density function of a Largest Extreme Value variable
2427 * is defined as:
2428 *
2429 * \f[
2430 * P(x; \mu, \beta) dx = \frac{1}{\beta} e^{-(z+ e^{-z})} dx, \quad z = \frac{x - \mu}{\beta}
2431 * \f]
2432 *
2433 * where \f$\mu\f$ is the \c Location configurable attribute and \f$\beta\f$
2434 * is the \c Scale configurable attribute.
2435 *
2436 * The Largest Extreme Value RNG value \f$x\f$ is generated by
2437 *
2438 * \f[
2439 * x = \mu - \beta \log(-\log(u))
2440 * \f]
2441 *
2442 * where \f$u\f$ is a uniform random variable on [0,1).
2443 *
2444 * The mean of the distribution is:
2445 *
2446 * \f[
2447 * E = \mu + y \beta
2448 * \f]
2449 *
2450 * where \f$y\f$ is the Euler-Mascheroni constant.
2451 *
2452 * The variance of the distribution is
2453 *
2454 * \f[
2455 * \sigma^2 = 6 \pi^2 \beta^2
2456 * \f]
2457 */
2459{
2460 public:
2461 /**
2462 * @brief Register this type.
2463 * @return The object TypeId.
2464 */
2465 static TypeId GetTypeId();
2466
2467 /**
2468 * @brief Creates a Largest Extreme Value distribution RNG with the default
2469 * values for the location and the scale.
2470 */
2472
2473 /**
2474 * @brief Get the configured location value of this RNG.
2475 *
2476 * @return The configured location value.
2477 */
2478 double GetLocation() const;
2479
2480 /**
2481 * @brief Get the configured scale value of this RNG.
2482 *
2483 * @return The configured scale value.
2484 */
2485 double GetScale() const;
2486
2487 /**
2488 * @copydoc GetValue()
2489 * @param [in] location location value of the Largest Extreme Value distribution.
2490 * @param [in] scale scale value of the Largest Extreme Value distribution.
2491 */
2492 double GetValue(double location, double scale);
2493
2494 /** @copydoc GetValue(double,double) */
2495 uint32_t GetInteger(uint32_t location, uint32_t scale);
2496
2497 // Inherited
2498 double GetValue() override;
2500
2501 /**
2502 * @brief Returns the mean value for the Largest Extreme Value distribution returned by this RNG
2503 * stream.
2504 * @return The mean value for the Largest Extreme Value distribution returned by this
2505 * RNG stream.
2506 */
2507 double GetMean() const;
2508
2509 /**
2510 * @copydoc GetMean()
2511 * @param [in] location location value of the Largest Extreme Value distribution.
2512 * @param [in] scale scale value of the Largest Extreme Value distribution.
2513 */
2514 static double GetMean(double location, double scale);
2515
2516 /**
2517 * @brief Returns the variance value for the Largest Extreme Value distribution returned by this
2518 * RNG stream.
2519 * @return The variance value for the Largest Extreme Value distribution returned by
2520 * this RNG stream.
2521 */
2522 double GetVariance() const;
2523
2524 /**
2525 * @copydoc GetVariance()
2526 * @param [in] scale scale value of the Largest Extreme Value distribution.
2527 */
2528 static double GetVariance(double scale);
2529
2530 private:
2531 /** The location value of the Largest Extreme Value distribution. */
2533
2534 /** The scale value of the Largest Extreme Value distribution. */
2535 double m_scale;
2536
2537 // end of class LargestExtremeValueRandomVariable
2538};
2539
2540} // namespace ns3
2541
2542#endif /* RANDOM_VARIABLE_STREAM_H */
Attribute helper (ATTRIBUTE_ )macros definition.
uint32_t r
uint32_t v
double GetValue() override
Get the next random value drawn from the distribution.
double m_probability
The probability of success.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
double m_probability
The probability of success in each trial.
double GetValue() override
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
uint32_t m_trials
The number of trials.
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.
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.
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.
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...
void Validate()
Check that the CDF is valid.
std::map< double, double > m_empCdf
The map of CDF points (x, F(x)).
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.
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.
double GetValue() override
Get the next random value drawn from the distribution.
uint32_t GetInteger(uint32_t alpha, uint32_t beta)
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.
double m_location
The location value of the laplacian distribution.
double GetValue() override
Get the next random value drawn from the distribution.
double GetBound() const
Get the configured bound of this RNG.
static TypeId GetTypeId()
Register this type.
double m_bound
The bound on values that can be returned by this RNG stream.
LaplacianRandomVariable()
Creates an unbounded laplacian distribution RNG with the default values for the location and the scal...
double GetLocation() const
Get the configured location value of this RNG.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_scale
The scale value of the laplacian distribution.
double GetScale() const
Get the configured scale value of this RNG.
double GetVariance() const
Returns the variance value for the laplacian distribution returned by this RNG stream.
double m_scale
The scale value of the Largest Extreme Value distribution.
double GetMean() const
Returns the mean value for the Largest Extreme Value distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
LargestExtremeValueRandomVariable()
Creates a Largest Extreme Value distribution RNG with the default values for the location and the sca...
double GetVariance() const
Returns the variance value for the Largest Extreme Value distribution returned by this RNG stream.
double GetScale() const
Get the configured scale value of this RNG.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double GetLocation() const
Get the configured location value of this RNG.
double m_location
The location value of the Largest Extreme Value distribution.
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.
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 GetStdDev() const
Returns the standard deviation value for the normal distribution returned by this RNG stream.
double GetVariance() const
Returns the variance value for the normal distribution returned by this RNG stream.
void SetStdDev(double stdDev)
Set standard deviation of this normal distribution 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 constexpr 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.
Object()
Constructor.
Definition object.cc:96
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.
Definition ptr.h:67
static TypeId GetTypeId()
Register this type.
RngStream * Peek() const
Get the pointer to the underlying RngStream.
RandomVariableStream & operator=(const RandomVariableStream &)=delete
bool IsAntithetic() const
Check if antithetic values will be generated.
RandomVariableStream(const RandomVariableStream &)=delete
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.
Combined Multiple-Recursive Generator MRG32k3a.
Definition rng-stream.h:39
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.
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.
Definition type-id.h:49
UniformRandomVariable()
Creates a uniform distribution RNG with the default range.
uint32_t GetInteger() override
Get the next random value drawn from the distribution.
double GetMax() const
Get the upper bound on values returned by GetValue().
double m_min
The lower bound on values that can be returned by this RNG stream.
double m_max
The upper bound on values that can be returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
double GetMin() const
Get the lower bound on randoms returned by GetValue().
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 GetMean() const
Returns the mean value 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.
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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::TypeId declaration; inline and template implementations.