let GlobalValue do RNG environment variable processing
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 25 Feb 2009 12:27:00 -0500
changeset 4244 7c98934dcccd
parent 4243 d84e644c9692
child 4245 49d337cba9db
child 4263 fec2f830d015
let GlobalValue do RNG environment variable processing
src/core/rng-stream.cc
--- a/src/core/rng-stream.cc	Wed Feb 25 13:40:06 2009 +0100
+++ b/src/core/rng-stream.cc	Wed Feb 25 12:27:00 2009 -0500
@@ -201,58 +201,14 @@
     }
 }
 
-//two seeding methods follow
-ns3::IntegerValue GetSeedFromEnv ()
-{
-  uint32_t seed;
-  char *tmp = getenv ("NS_RNG");
-  // NS_RNG should be set
-  NS_ASSERT(tmp != 0);
-  std::string var = std::string (tmp);
-  std::string::size_type colon = var.find (":");
-  if (colon != std::string::npos)
-  {
-    std::string seedString = var.substr (0, colon);
-    std::istringstream iss;
-    iss.str (seedString);
-    iss >> seed;
-  }
-  else
-  {
-    std::istringstream iss;
-    iss.str (var);
-    iss >> seed;
-  }
-  // finally, actually use these values to do something.
-  return ns3::IntegerValue(seed);
-}
-
-ns3::IntegerValue GetRunFromEnv ()
-{
-  uint32_t run = 0;
-  char *tmp = getenv ("NS_RNG");
-  if (tmp != 0)
-  {
-    std::string var = std::string (tmp);
-    std::string::size_type colon = var.find (":");
-    if (colon != std::string::npos)
-    {
-      std::string runString = var.substr (colon+1,var.size ()-colon-1);
-      std::istringstream iss;
-      iss.str (runString);
-      iss >> run;
-    }
-  }
-  return run;  
-}
 
 static ns3::GlobalValue g_rngSeed ("RngSeed", 
                                    "The global seed of all rng streams",
-                                   (getenv ("NS_RNG") !=0) ? GetSeedFromEnv() : ns3::IntegerValue (1),
+                                   ns3::IntegerValue (1),
                                    ns3::MakeIntegerChecker<uint32_t> ());
 static ns3::GlobalValue g_rngRun ("RngRun", 
                                   "The run number used to modify the global seed",
-                                  (getenv ("NS_RNG") !=0) ? GetRunFromEnv() : ns3::IntegerValue (1),
+                                  ns3::IntegerValue (1),
                                   ns3::MakeIntegerChecker<uint32_t> ());
 
 } // end of anonymous namespace
@@ -354,48 +310,12 @@
     {
       initialized = true;
       uint32_t seed;
-      // First, initialize ourselves from the global value.
-      {
-        IntegerValue value;
-        g_rngSeed.GetValue (value);
-        seed = value.Get ();
-        g_rngRun.GetValue (value);
-        run = value.Get ();
-      }
-      // then, in case we have NS_RNG set, override the global 
-      // value from the env var.
-      char *tmp = getenv ("NS_RNG");
-      if (tmp != 0)
-        {
-          std::string var = std::string (getenv ("NS_RNG"));
-          std::string::size_type colon = var.find (":");
-          if (colon != std::string::npos)
-            {
-              {
-                std::string seedString = var.substr (0, colon);
-                std::istringstream iss;
-                iss.str (seedString);
-                iss >> seed;
-              }
-              {
-                std::string runString = var.substr (colon+1,var.size ()-colon-1);
-                std::istringstream iss;
-                iss.str (runString);
-                iss >> run;
-              }
-            }
-          else
-            {
-              {
-                std::istringstream iss;
-                iss.str (var);
-                iss >> seed;
-              }
-            }
-        }
-      // finally, actually use these values to do something.
-      uint32_t seedArray [] = {seed, seed, seed, seed, seed, seed};
-      SetPackageSeed (seedArray);
+      IntegerValue value;
+      g_rngSeed.GetValue (value);
+      seed = value.Get ();
+      g_rngRun.GetValue (value);
+      run = value.Get ();
+      SetPackageSeed (seed);
     }
   return run;
 }
@@ -419,18 +339,7 @@
 //
 RngStream::RngStream ()
 {
-  static bool globalSeedInitialized = false;
-  //get the global seed and initialize the RngStream system with it
-  IntegerValue tmp;
-  if (!globalSeedInitialized)
-  {
-    g_rngSeed.GetValue (tmp);
-    SetPackageSeed (tmp.Get());
-    globalSeedInitialized = true;
-  }
-  //get the global run number
-  g_rngRun.GetValue (tmp);
-  uint32_t run = tmp.Get ();
+  uint32_t run = EnsureGlobalInitialized ();
   
   anti = false;
   incPrec = false;