![]() |
![]() |
#include <FWCore/Utilities/interface/RandomNumberGenerator.h>
Usage: This class is the abstract interface to a Service which provides access to the CLHEP random number engines which are used generate random numbers. One accesses the service using the Service system.
edm::Service<RandomNumberGenerator> rng; CLHEP::HepRandomEngine& engine = rng->getEngine();
Alternately, one can access seeds that can be used to initialize random number engines. This option is mainly provided for backward compatibility as the getEngine function above did not exist until a lot of code that uses this mySeed function had already been written. Note this only returns one seed. It has been historically used to initialize the CLHEP::HepJamesRandom engine which only requires one seed.
edm::Service<RandomNumberGenerator> rng; uint32_t seed = rng->mySeed();
The RandomNumberGenerator automatically knows what module is requesting an engine or a seed and will return the proper one for that module.
When a separate Producer module is also included in the path the state of all the engines managed by this service can be saved to the event. Then in a later process, the RandomNumberGenerator is capable of restoring the state of the engines from the event in order to be able to exactly reproduce the earlier process. (Currently, this restore only works when random numbers are only generated in modules and not in the source).