Replace various instances of RandomVariable with RandomVariableStream
authorMitch Watrous
Mon, 20 Aug 2012 14:25:35 -0700
changeset 8996 d0e0a162a990
parent 8995 b86c8ccff7a6
child 8997 9222fc5291ca
Replace various instances of RandomVariable with RandomVariableStream
examples/matrix-topology/matrix-topology.cc
examples/routing/manet-routing-compare.cc
examples/wireless/multirate.cc
src/core/examples/sample-simulator.cc
src/core/examples/sample-simulator.py
src/core/test/attribute-test-suite.cc
src/dsdv/examples/dsdv-manet.cc
src/dsr/examples/dsr.cc
src/flow-monitor/examples/wifi-olsr-flowmon.py
src/lte/examples/lena-profiling.cc
src/lte/examples/lena-rem-sector-antenna.cc
src/mpi/examples/nms-p2p-nix-distributed.cc
src/netanim/examples/dynamic_linknode.cc
src/netanim/examples/uan-animation.cc
src/network/examples/droptail_vs_red.cc
src/network/model/application.cc
src/network/test/buffer-test.cc
src/network/utils/error-model.cc
src/nix-vector-routing/examples/nms-p2p-nix.cc
src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc
src/topology-read/examples/topology-example-sim.cc
src/virtual-net-device/examples/virtual-net-device.cc
--- a/examples/matrix-topology/matrix-topology.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/examples/matrix-topology/matrix-topology.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -243,15 +243,17 @@
               // same time. This rn is added to AppStartTime to have the sources
               // start at different time, however they will still send at the same rate.
 
-              UniformVariable x (0,1);
-              double rn = x.GetValue ();
+              Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
+              x->SetAttribute ("Min", DoubleValue (0));
+              x->SetAttribute ("Max", DoubleValue (1));
+              double rn = x->GetValue ();
               Ptr<Node> n = nodes.Get (j);
               Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
               Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0);
               Ipv4Address ip_addr = ipv4_int_addr.GetLocal ();
               OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (ip_addr, port)); // traffic flows from node[i] to node[j]
-              onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable  (1)));
-              onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+              onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+              onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
               ApplicationContainer apps = onoff.Install (nodes.Get (i));  // traffic sources are installed on all nodes
               apps.Start (Seconds (AppStartTime + rn));
               apps.Stop (Seconds (AppStopTime));
--- a/examples/routing/manet-routing-compare.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/examples/routing/manet-routing-compare.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -340,8 +340,8 @@
   adhocInterfaces = addressAdhoc.Assign (adhocDevices);
 
   OnOffHelper onoff1 ("ns3::UdpSocketFactory",Address ());
-  onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable  (1)));
-  onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+  onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+  onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
 
   for (int i = 0; i <= nSinks - 1; i++)
     {
@@ -350,9 +350,9 @@
       AddressValue remoteAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), port));
       onoff1.SetAttribute ("Remote", remoteAddress);
 
-      UniformVariable var;
+      Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
       ApplicationContainer temp = onoff1.Install (adhocNodes.Get (i + nSinks));
-      temp.Start (Seconds (var.GetValue (100.0,101.0)));
+      temp.Start (Seconds (var->GetValue (100.0,101.0)));
       temp.Stop (Seconds (TotalTime));
     }
 
--- a/examples/wireless/multirate.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/examples/wireless/multirate.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -53,7 +53,7 @@
 #include "ns3/applications-module.h"
 #include "ns3/mobility-module.h"
 #include "ns3/tools-module.h"
-#include "ns3/random-variable.h"
+#include "ns3/random-variable-stream.h"
 #include "ns3/wifi-module.h"
 #include "ns3/internet-module.h"
 #include "ns3/flow-monitor-helper.h"
@@ -253,12 +253,16 @@
 Experiment::SelectSrcDest (NodeContainer c)
 {
   uint32_t totalNodes = c.GetN ();
-  UniformVariable uvSrc (0, totalNodes/2 -1);
-  UniformVariable uvDest (totalNodes/2, totalNodes);
+  Ptr<UniformRandomVariable> uvSrc = CreateObject<UniformRandomVariable> ();
+  uvSrc->SetAttribute ("Min", DoubleValue (0));
+  uvSrc->SetAttribute ("Max", DoubleValue (totalNodes/2 -1));
+  Ptr<UniformRandomVariable> uvDest = CreateObject<UniformRandomVariable> ();
+  uvDest->SetAttribute ("Min", DoubleValue (totalNodes/2));
+  uvDest->SetAttribute ("Max", DoubleValue (totalNodes));
 
   for (uint32_t i=0; i < totalNodes/3; i++)
     {
-      ApplicationSetup (c.Get (uvSrc.RandomVariable::GetInteger ()), c.Get (uvDest.RandomVariable::GetInteger ()),  0, totalTime);
+      ApplicationSetup (c.Get (uvSrc->GetInteger ()), c.Get (uvDest->GetInteger ()),  0, totalTime);
     }
 }
 
@@ -273,21 +277,25 @@
 {
 
   // UniformVariable params: (Xrange, Yrange)
-  UniformVariable uv (0, c.GetN ());
+  Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable> ();
+  uv->SetAttribute ("Min", DoubleValue (0));
+  uv->SetAttribute ("Max", DoubleValue (c.GetN ()));
 
   // ExponentialVariable params: (mean, upperbound)
-  ExponentialVariable ev (expMean, totalTime);
+  Ptr<ExponentialRandomVariable> ev = CreateObject<ExponentialRandomVariable> ();
+  ev->SetAttribute ("Mean", DoubleValue (expMean));
+  ev->SetAttribute ("Bound", DoubleValue (totalTime));
 
   double start=0.0, stop=totalTime;
   uint32_t destIndex; 
 
   for (uint32_t i=0; i < c.GetN (); i++)
     {
-      stop = start + ev.GetValue ();
+      stop = start + ev->GetValue ();
       NS_LOG_DEBUG ("Start=" << start << " Stop=" << stop);
 
       do {
-          destIndex = (uint32_t) uv.GetValue ();
+          destIndex = (uint32_t) uv->GetValue ();
         } while ( (c.Get (destIndex))->GetId () == sender->GetId ());
 
       ApplicationSetup (sender, c.Get (destIndex),  start, stop);
@@ -420,8 +428,8 @@
       //Rectangle (xMin, xMax, yMin, yMax)
       mobil.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
                               "Bounds", RectangleValue (Rectangle (0, 500, 0, 500)),
-                              "Speed", RandomVariableValue (ConstantVariable (10)),
-                              "Pause", RandomVariableValue (ConstantVariable (0.2)));
+                              "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=10]"),
+                              "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));
     }
   mobil.Install (c);
 
--- a/src/core/examples/sample-simulator.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/core/examples/sample-simulator.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -22,7 +22,8 @@
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
 #include "ns3/command-line.h"
-#include "ns3/random-variable.h"
+#include "ns3/double.h"
+#include "ns3/random-variable-stream.h"
 
 using namespace ns3;
 
@@ -76,11 +77,13 @@
   cmd.Parse (argc, argv);
 
   MyModel model;
-  UniformVariable v = UniformVariable (10, 20);
+  Ptr<UniformRandomVariable> v = CreateObject<UniformRandomVariable> ();
+  v->SetAttribute ("Min", DoubleValue (10));
+  v->SetAttribute ("Max", DoubleValue (20));
 
   Simulator::Schedule (Seconds (10.0), &ExampleFunction, &model);
 
-  Simulator::Schedule (Seconds (v.GetValue ()), &RandomFunction);
+  Simulator::Schedule (Seconds (v->GetValue ()), &RandomFunction);
 
   EventId id = Simulator::Schedule (Seconds (30.0), &CancelledEvent);
   Simulator::Cancel (id);
--- a/src/core/examples/sample-simulator.py	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/core/examples/sample-simulator.py	Mon Aug 20 14:25:35 2012 -0700
@@ -44,7 +44,9 @@
 def main(dummy_argv):
 
     model = MyModel()
-    v = ns.core.UniformVariable(10,20)
+    v = ns.core.UniformRandomVariable()
+    v.SetAttribute("Min", ns.core.DoubleValue (10))
+    v.SetAttribute("Max", ns.core.DoubleValue (20))
 
     ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ExampleFunction, model)
 
--- a/src/core/test/attribute-test-suite.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/core/test/attribute-test-suite.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -24,7 +24,7 @@
 #include "ns3/config.h"
 #include "ns3/enum.h"
 #include "ns3/string.h"
-#include "ns3/random-variable.h"
+#include "ns3/random-variable-stream.h"
 #include "ns3/double.h"
 #include "ns3/object-vector.h"
 #include "ns3/object-map.h"
@@ -119,9 +119,9 @@
                                       TEST_B, "TestB",
                                       TEST_C, "TestC"))
       .AddAttribute ("TestRandom", "help text",
-                     RandomVariableValue (ConstantVariable (1.0)),
-                     MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
-                     MakeRandomVariableChecker ())
+                     StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
+                     MakePointerAccessor (&AttributeObjectTest::m_random),
+                     MakePointerChecker <RandomVariableStream>())
       .AddAttribute ("TestFloat", "help text",
                      DoubleValue (-1.1),
                      MakeDoubleAccessor (&AttributeObjectTest::m_float),
@@ -227,7 +227,7 @@
   uint8_t m_uint8;
   float m_float;
   enum Test_e m_enum;
-  RandomVariable m_random;
+  Ptr<RandomVariableStream> m_random;
   std::vector<Ptr<Derived> > m_vector1;
   std::vector<Ptr<Derived> > m_vector2;
   std::map <uint32_t, Ptr<Derived> > m_map1;
@@ -643,8 +643,39 @@
   NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
 }
 
-template <> void
-AttributeTestCase<RandomVariableValue>::DoRun (void)
+// ===========================================================================
+// Test the Attributes of type RandomVariableStream.
+// ===========================================================================
+class RandomVariableStreamAttributeTestCase : public TestCase
+{
+public:
+  RandomVariableStreamAttributeTestCase (std::string description);
+  virtual ~RandomVariableStreamAttributeTestCase () {}
+
+  void InvokeCbValue (int8_t a)
+  {
+    if (!m_cbValue.IsNull ()) {
+        m_cbValue (a);
+      }
+  }
+
+private:
+  virtual void DoRun (void);
+
+  Callback<void,int8_t> m_cbValue;
+
+  void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; }
+
+  int16_t m_gotCbValue;
+};
+
+RandomVariableStreamAttributeTestCase::RandomVariableStreamAttributeTestCase (std::string description)
+  : TestCase (description)
+{
+}
+
+void
+RandomVariableStreamAttributeTestCase::DoRun (void)
 {
   Ptr<AttributeObjectTest> p;
   bool ok;
@@ -653,16 +684,20 @@
   NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
 
   //
-  // Try to set a UniformVariable
+  // Try to set a UniformRandomVariable
   //
-  ok = p->SetAttributeFailSafe ("TestRandom", RandomVariableValue (UniformVariable (0., 1.)));
-  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
+  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformRandomVariable");
 
   //
-  // Try to set a <snicker> ConstantVariable
+  // Try to set a <snicker> ConstantRandomVariable
   //
-  ok = p->SetAttributeFailSafe ("TestRandom", RandomVariableValue (ConstantVariable (10.)));
-  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
+  //  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=10.0]"));
+  //ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+
+  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+
+  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a ConstantRandomVariable");
 }
 
 // ===========================================================================
@@ -1147,7 +1182,7 @@
 }
 
 // ===========================================================================
-// Test the Attributes of type CallbackVale.
+// Test the Attributes of type CallbackValue.
 // ===========================================================================
 class CallbackValueTestCase : public TestCase
 {
@@ -1244,7 +1279,7 @@
   AddTestCase (new AttributeTestCase<UintegerValue> ("Check Attributes of type UintegerValue"));
   AddTestCase (new AttributeTestCase<DoubleValue> ("Check Attributes of type DoubleValue"));
   AddTestCase (new AttributeTestCase<EnumValue> ("Check Attributes of type EnumValue"));
-  AddTestCase (new AttributeTestCase<RandomVariableValue> ("Check Attributes of type RandomVariableValue"));
+  AddTestCase (new RandomVariableStreamAttributeTestCase ("Check Attributes of type RandomVariableStream"));
   AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue"));
   AddTestCase (new ObjectMapAttributeTestCase ("Check Attributes of type ObjectMapValue"));
   AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue<uint8_t> can be set like IntegerValue"));
--- a/src/dsdv/examples/dsdv-manet.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/dsdv/examples/dsdv-manet.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -247,12 +247,17 @@
   MobilityHelper mobility;
   ObjectFactory pos;
   pos.SetTypeId ("ns3::RandomRectanglePositionAllocator");
-  pos.Set ("X", RandomVariableValue (UniformVariable (0, 1000)));
-  pos.Set ("Y", RandomVariableValue (UniformVariable (0, 1000)));
+  pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
+  pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
+
+  ostringstream speedConstantRandomVariableStream;
+  speedConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant="
+                                   << m_nodeSpeed
+                                   << "]";
 
   Ptr <PositionAllocator> taPositionAlloc = pos.Create ()->GetObject <PositionAllocator> ();
-  mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", RandomVariableValue (ConstantVariable (m_nodeSpeed)),
-                             "Pause", RandomVariableValue (ConstantVariable (2.0)), "PositionAllocator", PointerValue (taPositionAlloc));
+ mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", StringValue (speedConstantRandomVariableStream.str ()),
+                             "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=2.0]"), "PositionAllocator", PointerValue (taPositionAlloc));
   mobility.SetPositionAllocator (taPositionAlloc);
   mobility.Install (nodes);
 }
@@ -312,14 +317,14 @@
       for (uint32_t j = 0; j <= m_nSinks - 1; j++ )
         {
           OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (interfaces.GetAddress (j), port)));
-          onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
-          onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+          onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+          onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
 
           if (j != clientNode)
             {
               ApplicationContainer apps1 = onoff1.Install (nodes.Get (clientNode));
-              UniformVariable var;
-              apps1.Start (Seconds (var.GetValue (m_dataStart, m_dataStart + 1)));
+              Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
+              apps1.Start (Seconds (var->GetValue (m_dataStart, m_dataStart + 1)));
               apps1.Stop (Seconds (m_totalTime));
             }
         }
--- a/src/dsr/examples/dsr.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/dsr/examples/dsr.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -37,6 +37,7 @@
 #include "ns3/wifi-module.h"
 #include "ns3/internet-module.h"
 #include "ns3/dsr-module.h"
+#include <sstream>
 
 using namespace ns3;
 NS_LOG_COMPONENT_DEFINE ("DsrTest");
@@ -142,13 +143,24 @@
   MobilityHelper adhocMobility;
   ObjectFactory pos;
   pos.SetTypeId ("ns3::RandomRectanglePositionAllocator");
-  pos.Set ("X", RandomVariableValue (UniformVariable (0.0, 300.0)));
-  pos.Set ("Y", RandomVariableValue (UniformVariable (0.0, 1500.0)));
+  pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=300.0]"));
+  pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1500.0]"));
   Ptr<PositionAllocator> taPositionAlloc = pos.Create ()->GetObject<PositionAllocator> ();
 
+  ostringstream speedUniformRandomVariableStream;
+  speedUniformRandomVariableStream << "ns3::UniformRandomVariable[Min=0.0|Max="
+                                   << nodeSpeed
+                                   << "]";
+
+  ostringstream pauseConstantRandomVariableStream;
+  pauseConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant="
+                                   << pauseTime
+                                   << "]";
+
   adhocMobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel",
-                                  "Speed", RandomVariableValue (UniformVariable (0.0, nodeSpeed)),
-                                  "Pause", RandomVariableValue (ConstantVariable (pauseTime)),
+                                  //                                  "Speed", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=nodeSpeed]"),
+                                  "Speed", StringValue (speedUniformRandomVariableStream.str ()),
+                                  "Pause", StringValue (pauseConstantRandomVariableStream.str ()),
                                   "PositionAllocator", PointerValue (taPositionAlloc)
                                   );
   adhocMobility.Install (adhocNodes);
@@ -176,8 +188,8 @@
       apps_sink.Stop (Seconds (TotalTime));
 
       OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (allInterfaces.GetAddress (i), port)));
-      onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
-      onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+      onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+      onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
       onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize));
       onoff1.SetAttribute ("DataRate", DataRateValue (DataRate (rate)));
 
--- a/src/flow-monitor/examples/wifi-olsr-flowmon.py	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/flow-monitor/examples/wifi-olsr-flowmon.py	Mon Aug 20 14:25:35 2012 -0700
@@ -102,8 +102,9 @@
         #print i, destaddr
         onOffHelper.SetAttribute("Remote", ns.network.AddressValue(ns.network.InetSocketAddress(destaddr, port)))
         app = onOffHelper.Install(ns.network.NodeContainer(node))
-        app.Start(ns.core.Seconds(ns.core.UniformVariable(20, 30).GetValue()))
-            
+        urv = ns.core.UniformRandomVariable()
+        app.Start(ns.core.Seconds(urv.GetValue(20, 30)))
+
     #internet.EnablePcapAll("wifi-olsr")
     flowmon_helper = ns.flow_monitor.FlowMonitorHelper()
     #flowmon_helper.SetMonitorAttribute("StartTime", ns.core.TimeValue(ns.core.Seconds(31)))
--- a/src/lte/examples/lena-profiling.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/lte/examples/lena-profiling.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -116,14 +116,16 @@
       // Position of UEs attached to eNB
       for (uint32_t i = 0; i < nEnb; i++)
         {
-          UniformVariable posX (enbPosition.at(i).x - roomLength * 0.5,
-                                enbPosition.at(i).x + roomLength * 0.5);
-          UniformVariable posY (enbPosition.at(i).y - roomLength * 0.5,
-                                enbPosition.at(i).y + roomLength * 0.5);
+          Ptr<UniformRandomVariable> posX = CreateObject<UniformRandomVariable> ();
+          posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0.5));
+          posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0.5));
+          Ptr<UniformRandomVariable> posY = CreateObject<UniformRandomVariable> ();
+          posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0.5));
+          posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0.5));
           positionAlloc = CreateObject<ListPositionAllocator> ();
           for (uint32_t j = 0; j < nUe; j++)
             {
-              positionAlloc->Add (Vector (posX.GetValue (), posY.GetValue (), nodeHeight));
+              positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight));
               mobility.SetPositionAllocator (positionAlloc);
             }
           mobility.Install (ueNodes.at(i));
--- a/src/lte/examples/lena-rem-sector-antenna.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/lte/examples/lena-rem-sector-antenna.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -131,10 +131,12 @@
   // Position of UEs attached to eNB
   for (uint32_t i = 0; i < nEnb; i++)
     {
-      UniformVariable posX (enbPosition.at(i).x - roomLength * 0,
-                            enbPosition.at(i).x + roomLength * 0);
-      UniformVariable posY (enbPosition.at(i).y - roomLength * 0,
-                            enbPosition.at(i).y + roomLength * 0);
+      Ptr<UniformRandomVariable> posX = CreateObject<UniformRandomVariable> ();
+      posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0));
+      posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0));
+      Ptr<UniformRandomVariable> posY = CreateObject<UniformRandomVariable> ();
+      posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0));
+      posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0));
       positionAlloc = CreateObject<ListPositionAllocator> ();
       for (uint32_t j = 0; j < nUe; j++)
         {
@@ -152,7 +154,7 @@
             }
           else
             {
-              positionAlloc->Add (Vector (posX.GetValue (), posY.GetValue (), nodeHeight));
+              positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight));
             }
           mobility.SetPositionAllocator (positionAlloc);
         }
--- a/src/mpi/examples/nms-p2p-nix-distributed.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/mpi/examples/nms-p2p-nix-distributed.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -441,7 +441,7 @@
     }
   else
     {
-      UniformVariable urng;
+      Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
       int r1;
       double r2;
       for (uint32_t z = 0; z < nCN; ++z)
@@ -483,8 +483,8 @@
                   // Sources
                   if (systemCount == 1)
                     {
-                      r1 = 2 + (int)(4 * urng.GetValue ());
-                      r2 = 10 * urng.GetValue ();
+                      r1 = 2 + (int)(4 * urng->GetValue ());
+                      r2 = 10 * urng->GetValue ();
                       OnOffHelper client ("ns3::UdpSocketFactory", Address ());
 
                       AddressValue remoteAddress
@@ -497,8 +497,8 @@
                     }
                   else if (systemId == x % systemCount)
                     {
-                      r1 = 2 + (int)(4 * urng.GetValue ());
-                      r2 = 10 * urng.GetValue ();
+                      r1 = 2 + (int)(4 * urng->GetValue ());
+                      r2 = 10 * urng->GetValue ();
                       OnOffHelper client ("ns3::UdpSocketFactory", Address ());
 
                       AddressValue remoteAddress
@@ -543,8 +543,8 @@
                   // Sources
                   if (systemCount == 1)
                     {
-                      r1 = 2 + (int)(4 * urng.GetValue ());
-                      r2 = 10 * urng.GetValue ();
+                      r1 = 2 + (int)(4 * urng->GetValue ());
+                      r2 = 10 * urng->GetValue ();
                       OnOffHelper client ("ns3::UdpSocketFactory", Address ());
 
                       AddressValue remoteAddress
@@ -557,8 +557,8 @@
                     }
                   else if (systemId == x % systemCount)
                     {
-                      r1 = 2 + (int)(4 * urng.GetValue ());
-                      r2 = 10 * urng.GetValue ();
+                      r1 = 2 + (int)(4 * urng->GetValue ());
+                      r2 = 10 * urng->GetValue ();
                       OnOffHelper client ("ns3::UdpSocketFactory", Address ());
 
                       AddressValue remoteAddress
--- a/src/netanim/examples/dynamic_linknode.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/netanim/examples/dynamic_linknode.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -133,9 +133,9 @@
   // Install on/off app on all right side nodes
   OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
   clientHelper.SetAttribute 
-    ("OnTime", RandomVariableValue (UniformVariable (0, 1)));
+    ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
   clientHelper.SetAttribute 
-    ("OffTime", RandomVariableValue (UniformVariable (0, 1)));
+    ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
   ApplicationContainer clientApps;
 
   for (uint32_t i = 0; i < d.RightCount (); ++i)
--- a/src/netanim/examples/uan-animation.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/netanim/examples/uan-animation.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -99,11 +99,13 @@
 
   NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Updating positions");
   NodeContainer::Iterator it = nodes.Begin ();
-  UniformVariable uv (0, m_boundary);
+  Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable> ();
+  uv->SetAttribute ("Min", DoubleValue (0.0));
+  uv->SetAttribute ("Max", DoubleValue (m_boundary));
   for (; it != nodes.End (); it++)
     {
       Ptr<MobilityModel> mp = (*it)->GetObject<MobilityModel> ();
-      mp->SetPosition (Vector (uv.GetValue (), uv.GetValue (), 70.0));
+      mp->SetPosition (Vector (uv->GetValue (), uv->GetValue (), 70.0));
     }
 }
 
@@ -147,15 +149,17 @@
   Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator> ();
 
   {
-    UniformVariable urv (0, m_boundary);
+    Ptr<UniformRandomVariable> urv = CreateObject<UniformRandomVariable> ();
+    urv->SetAttribute ("Min", DoubleValue (0.0));
+    urv->SetAttribute ("Max", DoubleValue (m_boundary));
     pos->Add (Vector (m_boundary / 2.0, m_boundary / 2.0, m_depth));
     double rsum = 0;
 
     double minr = 2 * m_boundary;
     for (uint32_t i = 0; i < m_numNodes; i++)
       {
-        double x = urv.GetValue ();
-        double y = urv.GetValue ();
+        double x = urv->GetValue ();
+        double y = urv->GetValue ();
         double newr = sqrt ((x - m_boundary / 2.0) * (x - m_boundary / 2.0)
                             + (y - m_boundary / 2.0) * (y - m_boundary / 2.0));
         rsum += newr;
@@ -179,8 +183,8 @@
     socket.SetProtocol (0);
 
     OnOffHelper app ("ns3::PacketSocketFactory", Address (socket));
-    app.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
-    app.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+    app.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+    app.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
     app.SetAttribute ("DataRate", DataRateValue (m_dataRate));
     app.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
 
--- a/src/network/examples/droptail_vs_red.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/network/examples/droptail_vs_red.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -116,8 +116,8 @@
 
   // Install on/off app on all right side nodes
   OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
-  clientHelper.SetAttribute ("OnTime", RandomVariableValue (UniformVariable (0, 1)));
-  clientHelper.SetAttribute ("OffTime", RandomVariableValue (UniformVariable (0, 1)));
+  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
   Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
   PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
   ApplicationContainer sinkApps; 
--- a/src/network/model/application.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/network/model/application.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -24,7 +24,6 @@
 #include "application.h"
 #include "ns3/node.h"
 #include "ns3/nstime.h"
-#include "ns3/random-variable.h"
 #include "ns3/simulator.h"
 
 using namespace std;
--- a/src/network/test/buffer-test.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/network/test/buffer-test.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -1,5 +1,6 @@
 #include "ns3/buffer.h"
-#include "ns3/random-variable.h"
+#include "ns3/random-variable-stream.h"
+#include "ns3/double.h"
 #include "ns3/test.h"
 
 namespace ns3 {
@@ -247,7 +248,9 @@
   {
     const uint32_t actualSize = 72602;
     const uint32_t chunkSize = 67624;
-    UniformVariable bytesRng (0, 256);
+    Ptr<UniformRandomVariable> bytesRng = CreateObject<UniformRandomVariable> ();
+    bytesRng->SetAttribute ("Min", DoubleValue (0));
+    bytesRng->SetAttribute ("Max", DoubleValue (256));
 
     Buffer inputBuffer;
     Buffer outputBuffer;
@@ -256,7 +259,7 @@
     {
       Buffer::Iterator iter = inputBuffer.Begin ();
       for (uint32_t i = 0; i < actualSize; i++)
-        iter.WriteU8 (static_cast<uint8_t> (bytesRng.GetValue ()));
+        iter.WriteU8 (static_cast<uint8_t> (bytesRng->GetValue ()));
     }
 
     outputBuffer.AddAtEnd (chunkSize);
--- a/src/network/utils/error-model.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/network/utils/error-model.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -59,7 +59,6 @@
 #include "ns3/packet.h"
 #include "ns3/assert.h"
 #include "ns3/log.h"
-#include "ns3/random-variable.h"
 #include "ns3/boolean.h"
 #include "ns3/enum.h"
 #include "ns3/double.h"
--- a/src/nix-vector-routing/examples/nms-p2p-nix.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/nix-vector-routing/examples/nms-p2p-nix.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -435,9 +435,9 @@
   cout << "Creating TCP Traffic Flows:" << endl;
   Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
   Config::SetDefault ("ns3::OnOffApplication::OnTime",
-                      RandomVariableValue (ConstantVariable (1)));
+                      StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
   Config::SetDefault ("ns3::OnOffApplication::OffTime",
-                      RandomVariableValue (ConstantVariable (0)));
+                      StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
   Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
 
   UniformVariable urng;
--- a/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -29,7 +29,6 @@
 #include "ns3/data-rate.h"
 #include "ns3/inet-socket-address.h"
 #include "ns3/packet-sink.h"
-#include "ns3/random-variable.h"
 
 #include "ns3/wifi-helper.h"
 #include "ns3/qos-wifi-mac-helper.h"
--- a/src/topology-read/examples/topology-example-sim.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/topology-read/examples/topology-example-sim.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -152,9 +152,11 @@
 
 
   uint32_t totalNodes = nodes.GetN ();
-  UniformVariable unifRandom (0, totalNodes - 1);
+  Ptr<UniformRandomVariable> unifRandom = CreateObject<UniformRandomVariable> ();
+  unifRandom->SetAttribute ("Min", DoubleValue (0));
+  unifRandom->SetAttribute ("Max", DoubleValue (totalNodes - 1));
 
-  unsigned int randomServerNumber = unifRandom.GetInteger (0, totalNodes - 1);
+  unsigned int randomServerNumber = unifRandom->GetInteger (0, totalNodes - 1);
 
   Ptr<Node> randomServerNode = nodes.Get (randomServerNumber);
   Ptr<Ipv4> ipv4Server = randomServerNode->GetObject<Ipv4> ();
@@ -168,8 +170,8 @@
   InetSocketAddress dst = InetSocketAddress ( ipv4AddrServer );
 
   OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
-  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
-  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
+  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
   onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000)));
   onoff.SetAttribute ("PacketSize", UintegerValue (1200));
 
--- a/src/virtual-net-device/examples/virtual-net-device.cc	Mon Aug 20 11:54:03 2012 -0700
+++ b/src/virtual-net-device/examples/virtual-net-device.cc	Mon Aug 20 14:25:35 2012 -0700
@@ -71,7 +71,7 @@
   Ipv4Address m_n3Address;
   Ipv4Address m_n0Address;
   Ipv4Address m_n1Address;
-  UniformVariable m_rng;
+  Ptr<UniformRandomVariable> m_rng;
   Ptr<VirtualNetDevice> m_n0Tap;
   Ptr<VirtualNetDevice> m_n1Tap;
   Ptr<VirtualNetDevice> m_n3Tap;
@@ -96,7 +96,7 @@
   bool
   N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
   {
-    if (m_rng.GetValue () < 0.25)
+    if (m_rng->GetValue () < 0.25)
       {
         NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet);
         m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
@@ -142,6 +142,7 @@
           Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr)
     : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr)
   {
+    m_rng = CreateObject<UniformRandomVariable> ();
     m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory"));
     m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
     m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));