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