Message: Re: Seed for Random Engines Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

More Re: Seed for Random Engines 

Forum: Run Management
Re: Question Seed for Random Engines
Re: More Re: Seed for Random Engines (Gabriele Cosmo)
Re: Question Re: Seed for Random Engines (Asja Pfaffenberger)
Date: 05 Aug, 2011
From: Gabriele Cosmo <Gabriele Cosmo>

Hi Asja,

> I am just having a seed problem myself and found your reply looking for
> answers in the forum. - It seems to contradict what i see so i am
> wondering if there is something i am overlooking. I would be grateful if
> you (or somebody else) could have a quick look on the following lines.

there is no contradiction, but I see here there is a bit of confusion...

> In a modified version of the extended/medical/dicom example v.9.4.p02, i
> set in my main
> 
> > CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
> 
> pick a seed from the seed table according to a seedIndex which i change
> for every run:
> 
> > long seeds[2];
> > CLHEP::HepRandom::getTheTableSeeds(seeds,seedIndex);
> 
> use one of them to initialize random number generator
> 
> > CLHEP::HepRandom::setTheSeed(seeds[0]);

Here you're using a different method, setTheSeed() instead of setTheSeeds().
If you read the documentation for RanecuEngine, you'll see that SetTheSeed()
for Ranecu will simply set the "index" in the Table of seeds, index which is
normalized to 215, as the table has only 215 entries.

> Now, if i do a
> 
> > G4cout << "DicomPrimaryGeneratorAction::GeneratePrimaries: seed= " <<
> CLHEP::HepRandom::getTheSeed() << G4endl;
> 
> in DicomPrimaryGeneratorAction::GeneratePrimaries, i get "1" every time
> GeneratePrimaries is invoked.

What you get is again the "index" in the table..
The actual seeds are the -couple- of numbers 'seeds' you can get with:
  seeds = CLHEP::HepRandom::getTheSeeds();

> The sequence of G4UniformRand() numbers
> generated during the events of one run is then the same for every run,
> no matter what index i give in main. Is there something i am doing
> wrong? Or what should i check to find out?

For Ranecu, CLHEP::HepRandom::setTheSeed(index);
where 'index' is between 0 and 214, can provide only up to 215 different
seedings of the engine.
You can use CLHEP::HepRandom::setTheSeeds(seeds);
where 'seeds' is an array of a couple of numbers for seeding the engine
as you like (which is the same behavior you can achieve using the run-time
command being discussed previously in this thread...).

> I had an output of the seed[0] in main, which nicely gives the
> respective entry in SeedTable.h, while a G4cout of
> CLHEP::HepRandom::getTheSeed() in main, directly after the setTheSeed
> returns a different value (e.g. seeds[0]=1315342834, getTheSeed returns
> 139), but this changes with a different seeds[0] so i was not so
> concerned but still i do not understand why?

The index gets normalized, as I said above.
Though, note that all this applies only for Ranecu and Ranlux engines.
There're also faster or more advanced engines available in CLHEP you can choose...

Cheers, Gabriele

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Ok: Re: Seed for Random Engines   (Asja Pfaffenberger - 05 Aug, 2011)
(_ More: Re: Seed for Random Engines   (Gabriele Cosmo - 05 Aug, 2011)
 Add Message Add Message
to: "Re: Seed for Random Engines"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]