Random numbers don´t appear to be random

Dear Geant4 users, I am new to Geant4.

I am generating photons within a certain volume with the particle gun and the help of G4UniformRand() so that evey one has its particular starting position and starting momentum.
I have found that every ‘‘first’’ run generates the same random numbers. I get the same starting positions (x,y,z). I have to say that I only compared two consecutive ‘‘first’’ runs but they were of 100 photons.

Is two runs not enough to conclude that every next ‘‘first’’ run is going to generate the exact same numbers?
Is there another random number generator that can be used?

By ‘‘first’’ run I mean running the aplication for the first time with the user interface since launching it.

Thank you in advance.

You are correct that in Geant4, the random engine is seeded identically at the start of every job. That is done in order to support reproducibility for debugging, for regression testing, and so on.

Unfortunately, it is left to the end user to do other kinds of seeding. For our experiment, we wrote a little utility that uses UUID to generate a unique set of integers that we can pass as seeds to the random engine. Other people might use a job number, or the timestamp on their laptop, or whatever.

Thank you for the reply Michael. I will see if I manage to use a diferent generator.


Try this code, it can help you to obtain more or less random events.
CLHEP::HepRandom::setTheEngine(new CLHEP::MTwistEngine);

The first option:

generated the same random numbers for all the events. It only changed with new runs.

But the seccond option:

does generate random numbers that don´t repeat at the start of every job.

Thank you very much for the help!!

1 Like