TH2::GetRandom2 in multi-threaded application


I am using a TH2 histogram to store information for my Geant4 application. I call GetRandom2 on the TH2 within Geant to generate a pair of variables that define source characteristics for each of a large number of events. This works fine for a non-threaded application.

In the multi-threaded Geant application, I take a copy of the TH2 for each thread which should then calculate it’s share of events by calling GetRandom2 on it’s own copy of the histogram. My question is :- Are the random number sequences generated by the threaded calls to GetRandom2 independent? Should I be explicitly setting a seed in each thread somehow or will the default initialisation be sufficient? I do not see any obvious duplication of the output between the threads, but I would like to be sure I am doing the right thing.

Advice gratefully received


TH1::GetRandom uses a common global gRandom, which I guess will be shared between the threads. This I am sure it will create a problem, not so much on the sequence, but due to the fact that two threads will change at the same time its state.
The solution is to use different random generator instance, but at the moment the TH2::GetRandom2 interface does not support to pass an external TRandom * pointer. We will fix this soon for the next version

Best Regards