I am trying run a simulation in multi thread with automatically updating random seed with systime so that I can run it multiple times with same input and not to get a duplicated results. So I put this in my main.cc:
and I checked with
G4cout << "Seed: " << G4Random::getTheSeed() << G4endl;
to make sure that I have a different seeds every time.
However, when I run a compiled executable with a macro, and then I turn off the executable and rerun the executable with same macro again, it gives me the same result with previous run, even though the seed is shown differently.
Am I missing something? I am very new to programming, so I might have missed something should have been done.
This is discussed in the Geant4 documentation, but not in the Application Developers Guide. The Toolkit Developers Guide, which is generally aimed at G4 collaborators, has a whole section on multithreading, including guidance on how to initialize the random engine:
It seems like that I have to have a function like MyRunManager::InitializeSeeds and place it inside the BeginoOfRunaction of my RunAction.cc?
And to do so it requires number of events and number of seeds per event.
I could get number of events using NumberOfEventsToBeProcessed(), but how do I get the number of seeds per event in BeginOfRunAction?
In case this is of help: the seed needs to be set before G4MTRunManager is instantiated. G4MTRunManager contains a master random number generator which is used to generate the seeds for the events. This generator is cloned from G4Random::getTheEngine() when G4MTRunManager is instantiated.
This fixes the issue, without any need for overriding InitializeSeeds. I hope this helps!