A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rng-seed-manager.cc
1 #include "rng-seed-manager.h"
2 #include "global-value.h"
3 #include "attribute-helper.h"
4 #include "integer.h"
5 #include "config.h"
6 #include "log.h"
7 
8 NS_LOG_COMPONENT_DEFINE ("RngSeedManager");
9 
10 namespace ns3 {
11 
12 static uint64_t g_nextStreamIndex = 0;
13 static ns3::GlobalValue g_rngSeed ("RngSeed",
14  "The global seed of all rng streams",
16  ns3::MakeIntegerChecker<uint32_t> ());
17 static ns3::GlobalValue g_rngRun ("RngRun",
18  "The run number used to modify the global seed",
20  ns3::MakeIntegerChecker<int64_t> ());
21 
22 
23 uint32_t RngSeedManager::GetSeed (void)
24 {
26  IntegerValue seedValue;
27  g_rngSeed.GetValue (seedValue);
28  return seedValue.Get ();
29 }
30 void
31 RngSeedManager::SetSeed (uint32_t seed)
32 {
33  NS_LOG_FUNCTION (seed);
34  Config::SetGlobal ("RngSeed", IntegerValue(seed));
35 }
36 
37 void RngSeedManager::SetRun (uint64_t run)
38 {
39  NS_LOG_FUNCTION (run);
40  Config::SetGlobal ("RngRun", IntegerValue (run));
41 }
42 
44 {
46  IntegerValue value;
47  g_rngRun.GetValue (value);
48  int run = value.Get();
49  return run;
50 }
51 
52 uint64_t RngSeedManager::GetNextStreamIndex (void)
53 {
55  uint64_t next = g_nextStreamIndex;
56  g_nextStreamIndex++;
57  return next;
58 }
59 
60 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Hold a signed integer type.
Definition: integer.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
hold a so-called 'global value'.
Definition: global-value.h:47
static void SetRun(uint64_t run)
Set the run number of simulation.
static uint64_t GetRun(void)
static uint32_t GetSeed(void)
Get the seed value.
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:707
void GetValue(AttributeValue &value) const