Generating Random Numbers

I would like some help to fully understand what is happening when I try to generate random numbers is the example code I have attached. Specifically why the function test1() will give the same numbers each time through the loop.

Also, if you call the constructor with seed=0 or call SetSeed(0) does this really mean that every time you call Rndm() it will use a unique seed? Thanks :smiley:
RndmTest.C (771 Bytes)

When calling “TRandom3 rand” you create a generator always initialized with the same default seed.
When calling “TRandom3 rand(0)” you create a generator with a new seed generated by a UID (unique identifier in time and space).
In case of your test1, your statement “TRandom3 rand” is in the loop, therefore you keep recreating a new generator always set with the same seed.