This documentation is not the
Latest Release
.
A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
sample-random-variable.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*/
16
#include "ns3/simulator.h"
17
#include "ns3/nstime.h"
18
#include "ns3/command-line.h"
19
#include "ns3/random-variable-stream.h"
20
#include <iostream>
21
22
using namespace
ns3
;
23
24
/*
25
* This program can be run from waf such as "./waf --run sample-random-variable"
26
*
27
* This program is about as simple as possible to display the use of ns-3
28
* to generate random numbers. By default, the uniform random variate that
29
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
30
* pseudo-random number generator, this program should always output the
31
* same number. Likewise, ns-3 simulations using random variables will
32
* behave deterministically unless the user changes the RunNumber or the
33
* Seed.
34
*
35
* There are three primary mechanisms to change the seed or run numbers
36
* from their default integer value of 1
37
* 1) Through explicit call of SeedManager::SetSeed () and
38
* SeedManager::SetRun () (commented out below)
39
* 2) Through the passing of command line arguments such as:
40
* "./waf --command-template="%s --RngRun=<value>" --run program-name"
41
* 3) Through the use of the NS_GLOBAL_VALUE environment variable, such as:
42
* "NS_GLOBAL_VALUE="RngRun=<value>" ./waf --run program-name"
43
*
44
* For instance, setting the run number to 3 will change the program output to
45
* 0.775417
46
*
47
* Consult the ns-3 manual for more information about the use of the
48
* random number generator
49
*/
50
51
int
main (
int
argc,
char
*argv[])
52
{
53
CommandLine
cmd
;
54
cmd.
Parse
(argc, argv);
55
56
// SeedManager::SetRun (3);
57
58
Ptr<UniformRandomVariable>
uv = CreateObject<UniformRandomVariable> ();
59
60
std::cout << uv->
GetValue
() << std::endl;
61
62
}
ns3::Ptr< UniformRandomVariable >
second.cmd
tuple cmd
Definition:
second.py:35
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:201
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::UniformRandomVariable::GetValue
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
Definition:
random-variable-stream.cc:180
ns3::CommandLine::Parse
void Parse(int argc, char *argv[])
Parse the program arguments.
Definition:
command-line.cc:112
src
core
examples
sample-random-variable.cc
Generated on Wed Nov 11 2015 20:00:27 for ns-3 by
1.8.9.1