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