A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::RandomVariableStream Class Referenceabstract

The basic uniform Random Number Generator (RNG). More...

#include "random-variable-stream.h"

+ Inheritance diagram for ns3::RandomVariableStream:
+ Collaboration diagram for ns3::RandomVariableStream:

Public Member Functions

 RandomVariableStream ()
 Default constructor.
 
 RandomVariableStream (const RandomVariableStream &)=delete
 
 ~RandomVariableStream () override
 Destructor.
 
virtual uint32_t GetInteger ()
 Get the next random value drawn from the distribution.
 
int64_t GetStream () const
 Returns the stream number for the RngStream.
 
virtual double GetValue ()=0
 Get the next random value drawn from the distribution.
 
bool IsAntithetic () const
 Check if antithetic values will be generated.
 
RandomVariableStreamoperator= (const RandomVariableStream &)=delete
 
void SetAntithetic (bool isAntithetic)
 Specify whether antithetic values should be generated.
 
void SetStream (int64_t stream)
 Specifies the stream number for the RngStream.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

RngStreamPeek () const
 Get the pointer to the underlying RngStream.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoDispose ()
 Destructor implementation.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Private Attributes

bool m_isAntithetic
 Indicates if antithetic values should be generated by this RNG stream.
 
RngStreamm_rng
 Pointer to the underlying RngStream.
 
int64_t m_stream
 The stream number for the RngStream.
 

Additional Inherited Members

Detailed Description

The basic uniform Random Number Generator (RNG).

Note
The underlying random number generation method used by ns-3 is the RngStream code by Pierre L'Ecuyer at the University of Montreal.

ns-3 has a rich set of random number generators that allow stream numbers to be set deterministically if desired. Class RandomVariableStream defines the base class functionality required for all such random number generators.

By default, the underlying generator is seeded all the time with the same seed value and run number coming from the ns3::GlobalValue RngSeed and RngRun. Also by default, the stream number value for the underlying RngStream is automatically allocated.

Instances can be configured to return "antithetic" values. See the documentation for the specific distributions to see how this modifies the returned values.

Definition at line 89 of file random-variable-stream.h.

Constructor & Destructor Documentation

◆ RandomVariableStream() [1/2]

ns3::RandomVariableStream::RandomVariableStream ( )

Default constructor.

Definition at line 70 of file random-variable-stream.cc.

References NS_LOG_FUNCTION.

◆ ~RandomVariableStream()

ns3::RandomVariableStream::~RandomVariableStream ( )
override

Destructor.

Definition at line 76 of file random-variable-stream.cc.

References m_rng.

◆ RandomVariableStream() [2/2]

ns3::RandomVariableStream::RandomVariableStream ( const RandomVariableStream & )
delete

Member Function Documentation

◆ GetInteger()

uint32_t ns3::RandomVariableStream::GetInteger ( )
virtual

Get the next random value drawn from the distribution.

Returns
A random value.

Reimplemented in ns3::BernoulliRandomVariable, ns3::BinomialRandomVariable, ns3::ConstantRandomVariable, ns3::DeterministicRandomVariable, ns3::EmpiricalRandomVariable, ns3::ErlangRandomVariable, ns3::ExponentialRandomVariable, ns3::GammaRandomVariable, ns3::LaplacianRandomVariable, ns3::LargestExtremeValueRandomVariable, ns3::LogNormalRandomVariable, ns3::NormalRandomVariable, ns3::ParetoRandomVariable, ns3::SequentialRandomVariable, ns3::TriangularRandomVariable, ns3::UniformRandomVariable, ns3::WeibullRandomVariable, ns3::ZetaRandomVariable, and ns3::ZipfRandomVariable.

Definition at line 95 of file random-variable-stream.cc.

References ns3::Object::GetInstanceTypeId(), GetStream(), GetValue(), and NS_LOG_DEBUG.

Referenced by ns3::BurstErrorModel::DoCorrupt(), ns3::MeshPointDevice::GetForwardingDelay(), and ns3::lorawan::PeriodicSender::SendPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetStream()

int64_t ns3::RandomVariableStream::GetStream ( ) const

Returns the stream number for the RngStream.

Returns
The stream number for the RngStream. -1 means this stream was allocated automatically.

Definition at line 132 of file random-variable-stream.cc.

References m_stream.

Referenced by ns3::ErlangRandomVariable::GetExponentialValue(), ns3::BernoulliRandomVariable::GetInteger(), ns3::BinomialRandomVariable::GetInteger(), ns3::ConstantRandomVariable::GetInteger(), ns3::ErlangRandomVariable::GetInteger(), ns3::ExponentialRandomVariable::GetInteger(), ns3::LogNormalRandomVariable::GetInteger(), ns3::NormalRandomVariable::GetInteger(), ns3::ParetoRandomVariable::GetInteger(), GetInteger(), ns3::TriangularRandomVariable::GetInteger(), ns3::UniformRandomVariable::GetInteger(), ns3::UniformRandomVariable::GetInteger(), ns3::WeibullRandomVariable::GetInteger(), ns3::ZetaRandomVariable::GetInteger(), ns3::ZipfRandomVariable::GetInteger(), ns3::GammaRandomVariable::GetNormalValue(), GetTypeId(), ns3::BernoulliRandomVariable::GetValue(), ns3::BinomialRandomVariable::GetValue(), ns3::ConstantRandomVariable::GetValue(), ns3::DeterministicRandomVariable::GetValue(), ns3::EmpiricalRandomVariable::GetValue(), ns3::ErlangRandomVariable::GetValue(), ns3::ExponentialRandomVariable::GetValue(), ns3::GammaRandomVariable::GetValue(), ns3::LogNormalRandomVariable::GetValue(), ns3::NormalRandomVariable::GetValue(), ns3::ParetoRandomVariable::GetValue(), ns3::SequentialRandomVariable::GetValue(), ns3::TriangularRandomVariable::GetValue(), ns3::UniformRandomVariable::GetValue(), ns3::WeibullRandomVariable::GetValue(), ns3::ZetaRandomVariable::GetValue(), and ns3::ZipfRandomVariable::GetValue().

+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::RandomVariableStream::GetTypeId ( )
static

Register this type.

Returns
The object TypeId.

Definition at line 46 of file random-variable-stream.cc.

References GetStream(), IsAntithetic(), ns3::MakeBooleanAccessor(), ns3::MakeBooleanChecker(), ns3::MakeIntegerAccessor(), ns3::MakeIntegerChecker(), SetAntithetic(), ns3::TypeId::SetParent(), and SetStream().

+ Here is the call graph for this function:

◆ GetValue()

virtual double ns3::RandomVariableStream::GetValue ( )
pure virtual

Get the next random value drawn from the distribution.

Returns
A random value.

Implemented in ns3::BernoulliRandomVariable, ns3::BinomialRandomVariable, ns3::ConstantRandomVariable, ns3::DeterministicRandomVariable, ns3::EmpiricalRandomVariable, ns3::ErlangRandomVariable, ns3::ExponentialRandomVariable, ns3::GammaRandomVariable, ns3::LaplacianRandomVariable, ns3::LargestExtremeValueRandomVariable, ns3::LogNormalRandomVariable, ns3::NormalRandomVariable, ns3::ParetoRandomVariable, ns3::SequentialRandomVariable, ns3::TriangularRandomVariable, ns3::UniformRandomVariable, ns3::WeibullRandomVariable, ns3::ZetaRandomVariable, and ns3::ZipfRandomVariable.

Referenced by ns3::RandomWalk2dOutdoorMobilityModel::AvoidBuilding(), ns3::RandomDirection2dMobilityModel::BeginPause(), ns3::RandomWaypointMobilityModel::BeginWalk(), ns3::DhcpClient::Boot(), ns3::energy::BasicEnergyHarvester::CalculateHarvestedPower(), Bench::Cb(), ns3::RandomPropagationLossModel::DoCalcRxPower(), ns3::BurstErrorModel::DoCorrupt(), ns3::RateErrorModel::DoCorruptBit(), ns3::RateErrorModel::DoCorruptByte(), ns3::RateErrorModel::DoCorruptPkt(), ns3::Icmpv6L4Protocol::DoDAD(), ns3::RandomWalk2dOutdoorMobilityModel::DoInitializePrivate(), ns3::RandomWaypointMobilityModel::DoInitializePrivate(), ns3::RandomWalk2dMobilityModel::DrawRandomVelocityAndDistance(), ns3::RandomPropagationDelayModel::GetDelay(), GetInteger(), ns3::OutdoorPositionAllocator::GetNext(), ns3::RandomBoxPositionAllocator::GetNext(), ns3::RandomDiscPositionAllocator::GetNext(), ns3::RandomRectanglePositionAllocator::GetNext(), ns3::SequentialRandomVariable::GetValue(), ns3::ArpL3Protocol::Lookup(), ns3::SixLowPanNetDevice::ReceiveFromDevice(), ns3::DhcpClient::Request(), Bench::Run(), ns3::OnOffApplication::ScheduleStartEvent(), ns3::OnOffApplication::ScheduleStopEvent(), ns3::Icmpv6L4Protocol::SendNS(), ns3::Icmpv6L4Protocol::SendRS(), ns3::RandomDirection2dMobilityModel::SetDirectionAndSpeed(), ns3::GaussMarkovMobilityModel::Start(), and ns3::StaWifiMac::StartScanning().

+ Here is the caller graph for this function:

◆ IsAntithetic()

◆ operator=()

RandomVariableStream & ns3::RandomVariableStream::operator= ( const RandomVariableStream & )
delete

◆ Peek()

◆ SetAntithetic()

void ns3::RandomVariableStream::SetAntithetic ( bool isAntithetic)

Specify whether antithetic values should be generated.

Parameters
[in]isAntitheticIf true antithetic value will be generated.

Definition at line 82 of file random-variable-stream.cc.

References m_isAntithetic, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetStream()

void ns3::RandomVariableStream::SetStream ( int64_t stream)

Specifies the stream number for the RngStream.

Parameters
[in]streamThe stream number for the RngStream. -1 means "allocate a stream number automatically".

Definition at line 104 of file random-variable-stream.cc.

References ns3::Object::GetInstanceTypeId(), ns3::RngSeedManager::GetNextStreamIndex(), ns3::RngSeedManager::GetRun(), ns3::RngSeedManager::GetSeed(), m_rng, m_stream, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by ns3::ArpL3Protocol::AssignStreams(), ns3::BurstErrorModel::AssignStreams(), ns3::DhcpClient::AssignStreams(), ns3::energy::BasicEnergyHarvester::AssignStreams(), ns3::Icmpv6L4Protocol::AssignStreams(), ns3::MeshPointDevice::AssignStreams(), ns3::OnOffApplication::AssignStreams(), ns3::OutdoorPositionAllocator::AssignStreams(), ns3::RandomBoxPositionAllocator::AssignStreams(), ns3::RandomDiscPositionAllocator::AssignStreams(), ns3::RandomRectanglePositionAllocator::AssignStreams(), ns3::RateErrorModel::AssignStreams(), ns3::SixLowPanNetDevice::AssignStreams(), ns3::StaWifiMac::AssignStreams(), ns3::GaussMarkovMobilityModel::DoAssignStreams(), ns3::RandomDirection2dMobilityModel::DoAssignStreams(), ns3::RandomPropagationDelayModel::DoAssignStreams(), ns3::RandomPropagationLossModel::DoAssignStreams(), ns3::RandomWalk2dMobilityModel::DoAssignStreams(), ns3::RandomWalk2dOutdoorMobilityModel::DoAssignStreams(), ns3::RandomWaypointMobilityModel::DoAssignStreams(), and GetTypeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_isAntithetic

bool ns3::RandomVariableStream::m_isAntithetic
private

Indicates if antithetic values should be generated by this RNG stream.

Definition at line 158 of file random-variable-stream.h.

Referenced by IsAntithetic(), and SetAntithetic().

◆ m_rng

RngStream* ns3::RandomVariableStream::m_rng
private

Pointer to the underlying RngStream.

Definition at line 155 of file random-variable-stream.h.

Referenced by ~RandomVariableStream(), Peek(), and SetStream().

◆ m_stream

int64_t ns3::RandomVariableStream::m_stream
private

The stream number for the RngStream.

Definition at line 161 of file random-variable-stream.h.

Referenced by GetStream(), and SetStream().


The documentation for this class was generated from the following files: