A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
sample-random-variable.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*/
4
#include "ns3/command-line.h"
5
#include "ns3/nstime.h"
6
#include "ns3/random-variable-stream.h"
7
#include "ns3/simulator.h"
8
9
#include <iostream>
10
11
/**
12
* \file
13
* \ingroup core-examples
14
* \ingroup randomvariable
15
* Example program illustrating use of ns3::RandomVariable
16
*/
17
18
using namespace
ns3
;
19
20
/**
21
* This program can be run from ns3 such as
22
* `./ns3 run sample-random-variable`
23
*
24
* This program is about as simple as possible to display the use of ns-3
25
* to generate random numbers. By default, the uniform random variate that
26
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
27
* pseudo-random number generator, this program should always output the
28
* same number. Likewise, ns-3 simulations using random variables will
29
* behave deterministically unless the user changes the Run number or the
30
* Seed.
31
*
32
* There are three primary mechanisms to change the seed or run numbers
33
* from their default integer value of 1:
34
*
35
* 1. Through explicit call of SeedManager::SetSeed () and
36
* SeedManager::SetRun () (commented out below)
37
* 2. Through the passing of command line arguments such as:
38
* ./ns3 run program-name --command-template="%s --RngRun=<value>"`
39
* 3. Through the use of the NS_GLOBAL_VALUE environment variable, such as:
40
* `$ NS_GLOBAL_VALUE="RngRun=<value>" ./ns3 run program-name`
41
*
42
* For instance, setting the run number to 3 will change the program output to
43
* 0.775417
44
*
45
* Consult the ns-3 manual for more information about the use of the
46
* random number generator
47
*/
48
49
int
50
main(
int
argc,
char
* argv[])
51
{
52
CommandLine
cmd
(__FILE__);
53
cmd
.Parse(argc, argv);
54
55
// SeedManager::SetRun (3);
56
57
Ptr<UniformRandomVariable>
uv =
CreateObject<UniformRandomVariable>
();
58
59
std::cout << uv->GetValue() << std::endl;
60
61
return
0;
62
}
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
src
core
examples
sample-random-variable.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0