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
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*/
15
#include "ns3/command-line.h"
16
#include "ns3/nstime.h"
17
#include "ns3/random-variable-stream.h"
18
#include "ns3/simulator.h"
19
20
#include <iostream>
21
22
/**
23
* \file
24
* \ingroup core-examples
25
* \ingroup randomvariable
26
* Example program illustrating use of ns3::RandomVariable
27
*/
28
29
using namespace
ns3
;
30
31
/**
32
* This program can be run from ns3 such as
33
* `./ns3 run sample-random-variable`
34
*
35
* This program is about as simple as possible to display the use of ns-3
36
* to generate random numbers. By default, the uniform random variate that
37
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
38
* pseudo-random number generator, this program should always output the
39
* same number. Likewise, ns-3 simulations using random variables will
40
* behave deterministically unless the user changes the Run number or the
41
* Seed.
42
*
43
* There are three primary mechanisms to change the seed or run numbers
44
* from their default integer value of 1:
45
*
46
* 1. Through explicit call of SeedManager::SetSeed () and
47
* SeedManager::SetRun () (commented out below)
48
* 2. Through the passing of command line arguments such as:
49
* ./ns3 run program-name --command-template="%s --RngRun=<value>"`
50
* 3. Through the use of the NS_GLOBAL_VALUE environment variable, such as:
51
* `$ NS_GLOBAL_VALUE="RngRun=<value>" ./ns3 run program-name`
52
*
53
* For instance, setting the run number to 3 will change the program output to
54
* 0.775417
55
*
56
* Consult the ns-3 manual for more information about the use of the
57
* random number generator
58
*/
59
60
int
61
main(
int
argc,
char
* argv[])
62
{
63
CommandLine
cmd
(__FILE__);
64
cmd
.Parse(argc, argv);
65
66
// SeedManager::SetRun (3);
67
68
Ptr<UniformRandomVariable>
uv = CreateObject<UniformRandomVariable>();
69
70
std::cout << uv->GetValue() << std::endl;
71
72
return
0;
73
}
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
ns cmd
Definition:
second.py:40
src
core
examples
sample-random-variable.cc
Generated on Tue May 28 2024 23:34:23 for ns-3 by
1.9.6