Re: random generator and seed

From: Jason Detwiler <jadetwiler_at_lbl.gov>
Date: Fri, 4 Mar 2011 13:57:45 -0800


This should usually be fine but it depends on the generator. I have used TUUID to get a quick semi-random seed like this:

TUUID uuid;
UInt_t buffer[4];
uuid.GetUUID((UChar_t*) buffer);
UInt_t seed = (buffer[0] + buffer[1] + buffer[2] + buffer[3]);

// Negative seeds give nasty sequences for some engines. Might
// as well make all seeds positive; randomness is not really affected
// (one bit goes unused).

if (seed < 0) seed = -seed;

You throw out 3/4 of the info, but it should be very different from event to event. If you really need a good, different random seed from event-to-event, try reading from /dev/random (assuming you are on *nix):

ifstream devrandom("/dev/random");
UInt_t seed;
devrandom.read((char*)(&seed), sizeof(UInt_t));

The read can take some time but you will get a high quality random number every time.

Thanks,
Jason

On Fri, Mar 4, 2011 at 12:21 PM, Marc Escalier <escalier_at_lal.in2p3.fr> wrote:
> Hello,
>
> when one is using a random generator as, for example TRandom3,
> one can choose a given seed, with myrandom3.SetSeed(MyValue)
>
> one could do the following to make a smearing of a given variable inside a
> file, according to a gaussian centred to 0) :
>
> (option A) :
> myrandom3.SetSeed(a given seed);
> for (...) {
> ...
>  myrandom3.Gaus(0,a given value);
>  make the correction to the variable
> ...
> }
>
> (option B)
> for (...) {
> ...
>  myrandom3.SetSeed(TheEventNumberOfAFile); //for example one needs to smear
> a variable inside a file
> // for which each event has a different event number
>  myrandom3.Gaus(0,a given value);
>  make the correction to the variable
> ...
> }
>
> Is there a "pathology" in the option B in terms of distribution of the
> random numbers ?
>
> (there are no problems, just asking a naive question)
>
> thanks
>
>
Received on Fri Mar 04 2011 - 22:57:52 CET

This archive was generated by hypermail 2.2.0 : Sat Mar 05 2011 - 17:50:01 CET