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