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
using namespace
std;
26
27
/*
28
* This program can be run from waf such as "./waf --run sample-random-variable-stream"
29
*
30
* This program is about as simple as possible to display the use of ns-3
31
* to generate random numbers. By default, the uniform random variate that
32
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
33
* pseudo-random number generator, this program should always output the
34
* same number. Likewise, ns-3 simulations using random variables will
35
* behave deterministically unless the user changes the RunNumber or the
36
* Seed.
37
*
38
* There are three primary mechanisms to change the seed or run numbers
39
* from their default integer value of 1
40
* 1) Through explicit call of SeedManager::SetSeed () and
41
* SeedManager::SetRun () (commented out below)
42
* 2) Through the passing of command line arguments such as:
43
* "./waf --command-template="%s --RngRun=<value>" --run program-name"
44
* 3) Through the use of the NS_GLOBAL_VALUE environment variable, such as:
45
* "NS_GLOBAL_VALUE="RngRun=<value>" ./waf --run program-name"
46
*
47
* For instance, setting the run number to 3 will change the program output to
48
* 0.775417
49
*
50
* Consult the ns-3 manual for more information about the use of the
51
* random number generator
52
*/
53
54
int
main
(
int
argc,
char
*argv[])
55
{
56
CommandLine
cmd;
57
cmd.
Parse
(argc, argv);
58
59
// SeedManager::SetRun (3);
60
61
Ptr<UniformRandomVariable>
uv = CreateObject<UniformRandomVariable> ();
62
63
cout << uv->
GetValue
() << endl;
64
65
}
src
core
examples
sample-random-variable-stream.cc
Generated on Tue Oct 9 2012 16:45:34 for ns-3 by
1.8.1.2