A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uniform-random-bit-generator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8#ifndef UNIFORM_RANDOM_BIT_GENERATOR_H
9#define UNIFORM_RANDOM_BIT_GENERATOR_H
10
12
13#include <limits>
14
15namespace ns3
16{
17
18/**
19 * Wraps a UniformRandomVariable into a class that meets the requirements of a
20 * UniformRandomBitGenerator as specified by the C++11 standard, thus allowing
21 * the usage of ns-3 style UniformRandomVariables as generators in the functions
22 * of the standard random library.
23 */
25{
26 public:
31
32 /**
33 * \return the ns-3 style uniform random variable
34 */
36 {
37 return m_rv;
38 }
39
40 /// Typedef needed to meet requirements. Result type must be an unsigned integer type.
42
43 /**
44 * \return the smallest value that operator() may return
45 */
46 static constexpr result_type min()
47 {
48 return 0;
49 }
50
51 /**
52 * \return the largest value that operator() may return
53 */
54 static constexpr result_type max()
55 {
56 return std::numeric_limits<result_type>::max();
57 }
58
59 /**
60 * \return a value in the closed interval [min(), max()]
61 */
63 {
64 return m_rv->GetInteger(min(), max());
65 }
66
67 private:
68 Ptr<UniformRandomVariable> m_rv; //!< ns-3 style uniform random variable
69};
70
71} // namespace ns3
72
73#endif /* UNIFORM_RANDOM_BIT_GENERATOR_H */
Smart pointer class similar to boost::intrusive_ptr.
Wraps a UniformRandomVariable into a class that meets the requirements of a UniformRandomBitGenerator...
Ptr< UniformRandomVariable > m_rv
ns-3 style uniform random variable
Ptr< UniformRandomVariable > GetRv() const
The uniform distribution Random Number Generator (RNG).
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RandomVariableStream declaration, and related classes.