A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rng-seed-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Mathieu Lacage
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "rng-seed-manager.h"
9
10#include "attribute-helper.h"
11#include "config.h"
12#include "global-value.h"
13#include "log.h"
14#include "uinteger.h"
15
16/**
17 * \file
18 * \ingroup randomvariable
19 * ns3::RngSeedManager implementation.
20 */
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("RngSeedManager");
26
27/**
28 * \relates RngSeedManager
29 * The next random number generator stream number to use
30 * for automatic assignment.
31 */
32static uint64_t g_nextStreamIndex = 0;
33/**
34 * \relates RngSeedManager
35 * \anchor GlobalValueRngSeed
36 * The random number generator seed number global value. This is used to
37 * generate an new master PRNG sequence. It is typically not modified
38 * by user programs; the variable RngRun is preferred for independent
39 * replications.
40 *
41 * This is accessible as "--RngSeed" from CommandLine.
42 */
43static ns3::GlobalValue g_rngSeed("RngSeed",
44 "The global seed of all rng streams",
47/**
48 * \relates RngSeedManager
49 * \anchor GlobalValueRngRun
50 * The random number generator substream index. This is used to generate
51 * new PRNG sequences for all streams (random variables) in such a manner
52 * that the streams remain uncorrelated. Incrementing this variable can
53 * be used for independent replications.
54 *
55 * This is accessible as "--RngRun" from CommandLine.
56 */
57static ns3::GlobalValue g_rngRun("RngRun",
58 "The substream index used for all streams",
61
64{
66 UintegerValue seedValue;
67 g_rngSeed.GetValue(seedValue);
68 return static_cast<uint32_t>(seedValue.Get());
69}
70
71void
77
78void
80{
81 NS_LOG_FUNCTION(run);
82 Config::SetGlobal("RngRun", UintegerValue(run));
83}
84
85uint64_t
87{
89 UintegerValue value;
90 g_rngRun.GetValue(value);
91 uint64_t run = value.Get();
92 return run;
93}
94
95uint64_t
97{
99 uint64_t next = g_nextStreamIndex;
101 return next;
102}
103
104void
109
110} // namespace ns3
Attribute helper (ATTRIBUTE_ )macros definition.
Hold a so-called 'global value'.
void GetValue(AttributeValue &value) const
Get the value.
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 void ResetNextStreamIndex()
Resets the global stream index counter.
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:34
uint64_t Get() const
Definition uinteger.cc:26
Declaration of the various ns3::Config functions and classes.
ns3::GlobalValue declaration.
void SetGlobal(std::string name, const AttributeValue &value)
Definition config.cc:929
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
ns3::RngSeedManager declaration.
ns3::UintegerValue attribute value declarations and template implementations.