2009-12-28 09:43:08 -08:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
#include "ns3/command-line.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/nstime.h"
|
2014-10-13 16:09:59 -07:00
|
|
|
#include "ns3/random-variable-stream.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/simulator.h"
|
|
|
|
|
|
2009-12-28 09:43:08 -08:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2017-09-17 21:18:44 -07:00
|
|
|
/**
|
|
|
|
|
* \file
|
|
|
|
|
* \ingroup core-examples
|
|
|
|
|
* \ingroup randomvariable
|
|
|
|
|
* Example program illustrating use of ns3::RandomVariable
|
|
|
|
|
*/
|
|
|
|
|
|
2009-12-28 09:43:08 -08:00
|
|
|
using namespace ns3;
|
|
|
|
|
|
2017-09-17 21:18:44 -07:00
|
|
|
/**
|
2021-11-29 21:58:30 -03:00
|
|
|
* This program can be run from ns3 such as
|
2022-01-13 23:59:59 -03:00
|
|
|
* `./ns3 run sample-random-variable`
|
2020-03-27 16:40:58 -07:00
|
|
|
*
|
|
|
|
|
* This program is about as simple as possible to display the use of ns-3
|
2009-12-28 09:43:08 -08:00
|
|
|
* to generate random numbers. By default, the uniform random variate that
|
|
|
|
|
* will be outputted is 0.816532. Because ns-3 uses a fixed seed for the
|
|
|
|
|
* pseudo-random number generator, this program should always output the
|
|
|
|
|
* same number. Likewise, ns-3 simulations using random variables will
|
2017-09-17 21:18:44 -07:00
|
|
|
* behave deterministically unless the user changes the Run number or the
|
2011-05-13 14:52:27 -04:00
|
|
|
* Seed.
|
2020-03-27 16:40:58 -07:00
|
|
|
*
|
2009-12-28 09:43:08 -08:00
|
|
|
* There are three primary mechanisms to change the seed or run numbers
|
2017-09-17 21:18:44 -07:00
|
|
|
* from their default integer value of 1:
|
|
|
|
|
*
|
2020-03-27 16:40:58 -07:00
|
|
|
* 1. Through explicit call of SeedManager::SetSeed () and
|
|
|
|
|
* SeedManager::SetRun () (commented out below)
|
2017-09-17 21:18:44 -07:00
|
|
|
* 2. Through the passing of command line arguments such as:
|
2022-01-13 23:59:59 -03:00
|
|
|
* ./ns3 run program-name --command-template="%s --RngRun=<value>"`
|
2017-09-17 21:18:44 -07:00
|
|
|
* 3. Through the use of the NS_GLOBAL_VALUE environment variable, such as:
|
2022-01-13 23:59:59 -03:00
|
|
|
* `$ NS_GLOBAL_VALUE="RngRun=<value>" ./ns3 run program-name`
|
2020-03-27 16:40:58 -07:00
|
|
|
*
|
2009-12-28 09:43:08 -08:00
|
|
|
* For instance, setting the run number to 3 will change the program output to
|
|
|
|
|
* 0.775417
|
2020-03-27 16:40:58 -07:00
|
|
|
*
|
|
|
|
|
* Consult the ns-3 manual for more information about the use of the
|
2009-12-28 09:43:08 -08:00
|
|
|
* random number generator
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
int
|
|
|
|
|
main(int argc, char* argv[])
|
2009-12-28 09:43:08 -08:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
CommandLine cmd(__FILE__);
|
|
|
|
|
cmd.Parse(argc, argv);
|
2009-12-28 09:43:08 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
// SeedManager::SetRun (3);
|
2009-12-28 09:43:08 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
|
2011-05-13 14:52:27 -04:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
std::cout << uv->GetValue() << std::endl;
|
2009-12-28 09:43:08 -08:00
|
|
|
}
|