# GetRandom() give repeated values

Hello,

I would like to increase the statistic of a 1D histogram using GetRandom().

Here my initial histo:
TH1F *initial= new TH1F(“initial”,“energy histo”,1000,emin,emax);

and I filled a new histogram defined by
TH1F *highstat = new TH1F(“highstat”,“energy histo hs”,10000,emin,emax);

like this:
for (int i=1;i<=10000;i++) {
highstat->Fill(energy->GetRandom());
}

My problem is that, If I echo energy->GetRandom(), I see some repeated values (may be it is a problem of precision).
Do you know how I can avoid this ?
cheers

Could you provide a short script reproducing this problem and indicate which version of ROOT you use?
root.cern.ch/root/html514/TRandom.html

Rene

I am using Root Version 5.11/02 (19 April 2006) under mac os x10.4.
Here a short script which reproduce my problem (in attachement the input file energy.txt).
I will have a look on class TRandom .
Thank you
olivier
{
ifstream in_beam;
Double_t e;
Double_t emin=10000.,emax=0.;
in_beam.open(“energy.txt”);
TNtuple *low = new TNtuple(“low”,“ntuple energy”,“e”);
while (1)
{
in_beam >> e ;
if (!in_beam.good()) break;
low->Fill(e);
emin=TMath::Min(emin,e);
emax=TMath::Max(emax,e);
}
TH1F *energy = new TH1F(“energy”,“energy histo”,100,emin,emax);
low->Project(“energy”,“e”);
in_beam.close();

ofstream out_beam;
out_beam.open(“hs_energy.dat”);
for (int i=1;i<=5000;i++) {
out_beam << energy->GetRandom() << endl;
}
out_beam.close();
}
energy.txt (11.7 KB)

I cannot reproduce your problem. How did you check that you have several times the same value coming from GetRandom ?

I strongly suggest to move to the pro version 5.14. We introduced a new version of TRandom in 5.12

Rene

ok I will try the new 5.14 version.
Here what I did to check if there are some repeated values:

cat hs_energy.dat | sort | uniq -d | more

uniq -d Don’t output lines that are not repeated in the input

cheers
olivier

You do not write your “energy->GetRandom” numbers with enough precision on your output file. By defauly you get 6 or 7 significative digits. This is not enough in your example since your numbers are between 0 and 0.18.

Rene

Yes, this fixed my problem (I changed precision default to precision(14)).
thank you
cheers
olivier