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