A Discrete-Event Network Simulator
API
rng-seed-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Mathieu Lacage
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 
19 #include "rng-seed-manager.h"
20 
21 #include "attribute-helper.h"
22 #include "config.h"
23 #include "global-value.h"
24 #include "log.h"
25 #include "uinteger.h"
26 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("RngSeedManager");
37 
43 static uint64_t g_nextStreamIndex = 0;
54 static ns3::GlobalValue g_rngSeed("RngSeed",
55  "The global seed of all rng streams",
57  ns3::MakeUintegerChecker<uint32_t>());
68 static ns3::GlobalValue g_rngRun("RngRun",
69  "The substream index used for all streams",
71  ns3::MakeUintegerChecker<uint64_t>());
72 
73 uint32_t
75 {
77  UintegerValue seedValue;
78  g_rngSeed.GetValue(seedValue);
79  return static_cast<uint32_t>(seedValue.Get());
80 }
81 
82 void
84 {
85  NS_LOG_FUNCTION(seed);
86  Config::SetGlobal("RngSeed", UintegerValue(seed));
87 }
88 
89 void
91 {
92  NS_LOG_FUNCTION(run);
93  Config::SetGlobal("RngRun", UintegerValue(run));
94 }
95 
96 uint64_t
98 {
102  uint64_t run = value.Get();
103  return run;
104 }
105 
106 uint64_t
108 {
110  uint64_t next = g_nextStreamIndex;
112  return next;
113 }
114 
115 } // namespace ns3
Attribute helper (ATTRIBUTE_ )macros definition.
Hold a so-called 'global value'.
Definition: global-value.h:76
void GetValue(AttributeValue &value) const
Get the value.
Definition: global-value.cc:98
static void SetRun(uint64_t run)
Set the run number of simulation.
static ns3::GlobalValue g_rngRun("RngRun", "The substream index used for all streams", ns3::UintegerValue(1), ns3::MakeUintegerChecker< uint64_t >())
The random number generator substream index.
static ns3::GlobalValue g_rngSeed("RngSeed", "The global seed of all rng streams", ns3::UintegerValue(1), ns3::MakeUintegerChecker< uint32_t >())
The random number generator seed number global value.
static void SetSeed(uint32_t seed)
Set the seed.
static uint64_t GetNextStreamIndex()
Get the next automatically assigned stream index.
static uint64_t GetRun()
Get the current run number.
static uint64_t g_nextStreamIndex
The next random number generator stream number to use for automatic assignment.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
Declaration of the various ns3::Config functions and classes.
ns3::GlobalValue declaration.
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:937
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
value
Definition: second.py:41
ns3::RngSeedManager declaration.
ns3::UintegerValue attribute value declarations and template implementations.