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 "config.h"
11#include "global-value.h"
12#include "log.h"
13#include "uinteger.h"
14
15/**
16 * @file
17 * @ingroup randomvariable
18 * ns3::RngSeedManager implementation.
19 */
20
21namespace ns3
22{
23
24NS_LOG_COMPONENT_DEFINE("RngSeedManager");
25
26/**
27 * @relates RngSeedManager
28 * The next random number generator stream number to use
29 * for automatic assignment.
30 */
31static uint64_t g_nextStreamIndex = 0;
32/**
33 * @relates RngSeedManager
34 * @anchor GlobalValueRngSeed
35 * The random number generator seed number global value. This is used to
36 * generate an new master PRNG sequence. It is typically not modified
37 * by user programs; the variable RngRun is preferred for independent
38 * replications.
39 *
40 * This is accessible as "--RngSeed" from CommandLine.
41 */
42static ns3::GlobalValue g_rngSeed("RngSeed",
43 "The global seed of all rng streams",
46/**
47 * @relates RngSeedManager
48 * @anchor GlobalValueRngRun
49 * The random number generator substream index. This is used to generate
50 * new PRNG sequences for all streams (random variables) in such a manner
51 * that the streams remain uncorrelated. Incrementing this variable can
52 * be used for independent replications.
53 *
54 * This is accessible as "--RngRun" from CommandLine.
55 */
56static ns3::GlobalValue g_rngRun("RngRun",
57 "The substream index used for all streams",
60
63{
65 UintegerValue seedValue;
66 g_rngSeed.GetValue(seedValue);
67 return static_cast<uint32_t>(seedValue.Get());
68}
69
70void
76
77void
79{
80 NS_LOG_FUNCTION(run);
81 Config::SetGlobal("RngRun", UintegerValue(run));
82}
83
84uint64_t
86{
88 UintegerValue value;
89 g_rngRun.GetValue(value);
90 uint64_t run = value.Get();
91 return run;
92}
93
94uint64_t
96{
98 uint64_t next = g_nextStreamIndex;
100 return next;
101}
102
103void
108
109} // namespace ns3
Hold a so-called 'global 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:25
Declaration of the various ns3::Config functions and classes.
ns3::GlobalValue declaration.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
void SetGlobal(std::string name, const AttributeValue &value)
Definition config.cc:932
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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.
ns3::RngSeedManager declaration.
ns3::UintegerValue attribute value declarations and template implementations.