Problem 139 - A problem in the management of random number
Summary: A problem in the management of random number
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: global (show other problems)
Version: 2.0
Hardware: All All
: P1 major
Assignee: Gabriele Cosmo
URL:
Depends on:
Blocks:
 
Reported: 2000-07-24 04:18 CEST by Koichi Murakami
Modified: 2015-09-08 18:20 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
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);
                                                  
~                                                                               
~                                                                               
~                                                                               
~