Re: random generator and seed

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Sat, 5 Mar 2011 12:36:25 +0100


Hi ,

 If you in the constructor or in TRandom3::SetSeed a value of seed=0, a UUID is automatically generated inside and will give you a different generator event by event.
In the example provided by Jason, a UUID is used only for a single number of the 624 numbers which makes the state of TRandom3. When using SetSeed(0), 8 independent seeds are generated which gives a much lower probability of reproducing the sequence.

  Best Regards

 Lorenzo
On Mar 4, 2011, at 10:57 PM, Jason Detwiler wrote:

> 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 Sat Mar 05 2011 - 12:39:59 CET

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