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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
sample-random-variable-stream.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 University of Washington
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*/
18
#include "ns3/simulator.h"
19
#include "ns3/nstime.h"
20
#include "ns3/command-line.h"
21
#include "ns3/random-variable-stream.h"
22
#include <iostream>
23
24
using namespace
ns3;
25
26
/*
27
* This program can be run from waf such as "./waf --run sample-random-variable-stream"
28
*
29
* This program is about as simple as possible to display the use of ns-3
30
* to generate random numbers. By default, the uniform random variate that
31
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
32
* pseudo-random number generator, this program should always output the
33
* same number. Likewise, ns-3 simulations using random variables will
34
* behave deterministically unless the user changes the RunNumber or the
35
* Seed.
36
*
37
* There are three primary mechanisms to change the seed or run numbers
38
* from their default integer value of 1
39
* 1) Through explicit call of SeedManager::SetSeed () and
40
* SeedManager::SetRun () (commented out below)
41
* 2) Through the passing of command line arguments such as:
42
* "./waf --command-template="%s --RngRun=<value>" --run program-name"
43
* 3) Through the use of the NS_GLOBAL_VALUE environment variable, such as:
44
* "NS_GLOBAL_VALUE="RngRun=<value>" ./waf --run program-name"
45
*
46
* For instance, setting the run number to 3 will change the program output to
47
* 0.775417
48
*
49
* Consult the ns-3 manual for more information about the use of the
50
* random number generator
51
*/
52
53
int
main
(
int
argc,
char
*argv[])
54
{
55
CommandLine
cmd;
56
cmd.
Parse
(argc, argv);
57
58
// SeedManager::SetRun (3);
59
60
Ptr<UniformRandomVariable>
uv = CreateObject<UniformRandomVariable> ();
61
62
std::cout << uv->
GetValue
() << std::endl;
63
64
}
ns3::Ptr< UniformRandomVariable >
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:152
ns3::UniformRandomVariable::GetValue
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
Definition:
random-variable-stream.cc:172
main
int main(int argc, char *argv[])
Definition:
sample-random-variable-stream.cc:53
ns3::CommandLine::Parse
void Parse(int argc, char *argv[])
Definition:
command-line.cc:104
src
core
examples
sample-random-variable-stream.cc
Generated on Sun Apr 20 2014 11:14:46 for ns-3 by
1.8.6