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