From 4cd32401ecc4a487c33406daf9b644161550e88c Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 4 Dec 2014 12:14:46 -0800 Subject: [PATCH] clarify how to properly create random variable objects --- doc/manual/source/random-variables.rst | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/manual/source/random-variables.rst b/doc/manual/source/random-variables.rst index 3d6d8d37a..04028814d 100644 --- a/doc/manual/source/random-variables.rst +++ b/doc/manual/source/random-variables.rst @@ -105,6 +105,41 @@ use a single RNG and streams and substreams from it. .. _seeding-and-independent-replications: +Creating random variables +************************* + +|ns3| supports a number of random variable objects from the base class +:cpp:class:`RandomVariableStream`. These objects derive from +:cpp:class:`ns3::Object` and are handled by smart pointers. + +The correct way to create these objects is to use the templated +`CreateObject<>` method, such as: + +:: + + Ptr x = CreateObject (); + +then you can access values by calling methods on the object such as: + +:: + + myRandomNo = x->GetInteger (); + + +If you try to instead do something like this: + +:: + + myRandomNo = UniformRandomVariable().GetInteger (); + +your program will encounter a segmentation fault, because the implementation +relies on some attribute construction that occurs only when `CreateObject` +is called. + +Much of the rest of this chapter now discusses the properties of the +stream of pseudo-random numbers generated from such objects, and how to +control the seeding of such objects. + Seeding and independent replications ************************************