Random Seed

How does one set a seed for the random number generator?

That is, how do I get:

TH1F* h = new TH1F("test","test",8,0,50); h->FillRandom("gaus",50);
to give me a different plot every time the code is run.


By default you get a different distribution every time you call FillRandom.
This function uses the currently defined random generator pointed by gRandom (it is a TRandom3 object by default).


I get the same distribution every time I run the program. If I keep drawing new histograms the distribution changes, but the cycle is the same every time.

Of course if you run your program twice and by default you get teh same distribution. I imagine the disaster otherwise.
Please have a look at the TRandom, TRandom3 classes how to set a new seed every time you run the program, ie in your case call

gRandom = new TRandom3(0);
root.cern.ch/root/html/TRandom3. … 3:TRandom3


This is functionally equivalent to

gRandom->SetSeed (0);

except that you’re not leaking memory, right?