Index: /trunk/MagicSoft/Mars/mjobs/MJob.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 9243)
+++ /trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 9244)
@@ -40,6 +40,8 @@
 
 #include "MEnv.h"
+
 #include <TFile.h>
 #include <TSystem.h>
+#include <TRandom.h>
 #include <TObjArray.h>
 
@@ -225,5 +227,5 @@
 Int_t MJob::GetEnv(const char *name, Int_t dflt) const
 {
-    return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
+    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
 }
 
@@ -235,5 +237,5 @@
 Double_t MJob::GetEnv(const char *name, Double_t dflt) const
 {
-    return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
+    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
 }
 
@@ -245,5 +247,5 @@
 const char *MJob::GetEnv(const char *name, const char *dflt) const
 {
-    return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
+    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
 }
 
@@ -256,4 +258,50 @@
 {
     return IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2);//fEnv->Lookup(Form("%s%s", fEnvPrefix.Data(), name));
+}
+
+//------------------------------------------------------------------------
+//
+// Check fEnv for RadnomNumberGenerator. If it is empty or the
+// corresponding class does either not exist or not inherit from TRandom,
+// gRandom remains unchanged. Otherwise gRandom is set to a newly created
+// instance of this class.
+//
+// The second resource which is checked is RandomNumberSeedValue. If it
+// is empty (not given) the seed keeps unchanged. If a number is given
+// the seed value of gRandom is set accordingly. (0 means that
+// the seed value is set accoring to the time, see TRandom::SetSeed())
+//
+// If an error occured kFALSE is returned, kTRUE otherwise.
+//
+Bool_t MJob::InitRandomNumberGenerator() const
+{
+    const TString rng = GetEnv("RandomNumberGenerator", "");
+    if (!rng.IsNull())
+    {
+        TClass *cls = MParContainer::GetClass(rng, &gLog);
+        if (!cls)
+            return kFALSE;
+
+        if (!cls->InheritsFrom(TRandom::Class()))
+        {
+            *fLog << err << "ERROR - RandomNumberGenerator " << rng << " doesn't inherit from TRandom." <<  endl;
+            return kFALSE;
+        }
+
+        delete gRandom;
+        gRandom = static_cast<TRandom*>(cls->New());
+
+        *fLog << inf << "Random number generator " << rng << " initialized." << endl;
+    }
+
+    // Nothing: Keep seed value, 0 set time as seed value, val set seed
+    const TString seed = GetEnv("RandomNumberSeedNumber", "");
+    if (!seed.IsNull())
+    {
+        gRandom->SetSeed(seed.Atoi());
+        *fLog << inf << "Random number seed value set to " << seed.Atoi() << endl;
+    }
+
+    return kTRUE;
 }
 
@@ -266,4 +314,6 @@
 //   Overwrite
 //   EnvDebug
+//   RandomNumberGenerator
+//   RandomNumberSeedValue
 //
 // and call the virtual function CheckEnvLocal
@@ -273,4 +323,7 @@
     if (!fEnv)
         return kTRUE;
+
+    if (!InitRandomNumberGenerator())
+        return kFALSE;
 
     TString p;
