Problem 139

Summary: A problem in the management of random number
Product: Geant4 Reporter: Koichi Murakami <kmura>
Component: globalAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: major CC: billh
Priority: P1    
Version: 2.0   
Hardware: All   
OS: All   

Description Koichi Murakami 2000-07-24 04:18:53 CEST
I found a major problem in the management of random number.
This problem seems to be strongly coupled with CLHEP.

Currently it is impossible to reproduce an event, whose status of
random number is stored via "/run/storeRandomNumberStatus" command,
even if the status is restored via "/run/restoreRandomNumberStatus" command.

In my examination, this probrem is due to the implementation of
at least "RandFlat::shootBit()" and "RandGauss::shoot()" in CLHEP.
"RandFlat" class and "RandGauss" class have their own static members
for keeping their internal status.
So, even if store/restore a random engine, its sequence depends on
these "uncontrollable" variables whenever these methods are called.

Until now, I found at least the above two methods cause this problem.
Comment 1 Gabriele Cosmo 2000-07-25 11:17:59 CEST
Thanks for reporting the problem.
This is a known problem which has only recently been resolved in CLHEP 1.5
by providing alternative Gaussian random distribution algorithms.
Concerning Geant4, we did not manage to migrate the code in time for release
2.0. We plan to make this available in a minor release or patch.
Comment 2 Gabriele Cosmo 2000-08-07 07:34:59 CEST
All occurences of RandGauss have been replaced by G4RandGauss which
in turns now invokes CLHEP's RandGaussQ, which being stateless assures
reproducibility of gaussian random sequences (claimed to be also much
faster, though less accurate).
All occurences of RandFlat::shootBit() have been replaced by CLHEP's
RandBit::shootBit(), a simpler but less efficient implementation for
generating sequences of bits.
Comment 3 Gabriele Cosmo 2000-08-07 07:35:59 CEST
Fixes will be available in the public patch to Geant4 2.0.
Comment 4 Wm. Heintzelman 2015-09-08 18:20:17 CEST
                                                                              
The CLHEP code now has provision for saving and restoring the state of the
random number generator, including the cached data from RandGauss and RandFlat,
by using the functions HepRandom::saveStaticRandomStates and
HepRandom::restoreStaticRandomStates.  

To avoid problems for people that, not knowing about this issue, might use
RandGauss or RandFlat in their code, I suggest that the lines
    G4Random::saveFullState(oss);
in G4RunManager should be changed to
    G4Random::saveStaticRandomStates(oss);
                                                  
~                                                                               
~                                                                               
~                                                                               
~