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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6#include "ns3/command-line.h"
7#include "ns3/nstime.h"
8#include "ns3/random-variable-stream.h"
9#include "ns3/simulator.h"
10
11#include <iostream>
12
13/**
14 * \file
15 * \ingroup core-examples
16 * \ingroup randomvariable
17 * Example program illustrating use of ns3::RandomVariableStream
18 *
19 * This program can be run from ns3 such as
20 * `./ns3 run sample-random-variable-stream`
21 *
22 * This program is about as simple as possible to display the use of ns-3
23 * to generate random numbers. By default, the uniform random variate that
24 * will be printed is 0.816532. Because ns-3 uses a fixed seed for the
25 * pseudo-random number generator, this program should always output the
26 * same number. Likewise, ns-3 simulations using random variables will
27 * behave deterministically unless the user changes the Run number or the
28 * Seed.
29 *
30 * There are three primary mechanisms to change the seed or run numbers
31 * from their default integer value of 1:
32 *
33 * 1. Through explicit call of SeedManager::SetSeed () and
34 * SeedManager::SetRun () (commented out below)
35 * 2. Through the passing of command line arguments such as:
36 * `./ns3 run program-name --command-template="%s --RngRun=<value>"`
37 * 3. Through the use of the NS_GLOBAL_VALUE environment variable, such as:
38 * `$ NS_GLOBAL_VALUE="RngRun=<value>" ./ns3 run program-name`
39 *
40 * For instance, setting the run number to 3 will change the program output to
41 * 0.775417
42 *
43 * Consult the ns-3 manual for more information about the use of the
44 * random number generator
45 */
46
47using namespace ns3;
48
49int
50main(int argc, char* argv[])
51{
52 CommandLine cmd(__FILE__);
53 cmd.Parse(argc, argv);
54
55 // SeedManager::SetRun (3);
56
58
59 std::cout << uv->GetValue() << std::endl;
60
61 return 0;
62}
Parse command-line arguments.
Smart pointer class similar to boost::intrusive_ptr.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.