A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.h"
20 #include <iostream>
21 
22 using namespace ns3;
23 using namespace std;
24 
25 /*
26  * This program can be run from waf such as "./waf --run sample-random-variable"
27  *
28  * This program is about as simple as possible to display the use of ns-3
29  * to generate random numbers. By default, the uniform random variate that
30  * will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
31  * pseudo-random number generator, this program should always output the
32  * same number. Likewise, ns-3 simulations using random variables will
33  * behave deterministically unless the user changes the RunNumber or the
34  * Seed.
35  *
36  * There are three primary mechanisms to change the seed or run numbers
37  * from their default integer value of 1
38  * 1) Through explicit call of SeedManager::SetSeed () and
39  * SeedManager::SetRun () (commented out below)
40  * 2) Through the passing of command line arguments such as:
41  * "./waf --command-template="%s --RngRun=<value>" --run program-name"
42  * 3) Through the use of the NS_GLOBAL_VALUE environment variable, such as:
43  * "NS_GLOBAL_VALUE="RngRun=<value>" ./waf --run program-name"
44  *
45  * For instance, setting the run number to 3 will change the program output to
46  * 0.775417
47  *
48  * Consult the ns-3 manual for more information about the use of the
49  * random number generator
50  */
51 
52 int main (int argc, char *argv[])
53 {
54  CommandLine cmd;
55  cmd.Parse (argc, argv);
56 
57  // SeedManager::SetRun (3);
58 
59  UniformVariable uv;
60 
61  cout << uv.GetValue () << endl;
62 
63 }