Failing to generate more than one random number

Hi guys.

I am trying to generate a random number for each pdf in my root file. Problem is that I am generating the same number everytime. Here is the code

  for (list<RooAbsGenContext*>::iterator iter=_gcList.begin() ; iter!=_gcList.end() ; ++iter) {
if (theName == "RooGaussian") {
            Double_t xgen;
            RooGaussian *x_gaus = dynamic_cast<RooGaussian *>(_pdfClone);

            while (1) {
                TRandom *fv = new TRandom();
                xgen = fv->Gaus(x_gaus->x, x_gaus->sigma);
                if (xgen < x_gaus->mean.max() && xgen > x_gaus->mean.min()) {
                    x_gaus->mean = xgen;
                    cout << "THese are the generated"<< xgen<<endl;
                    break;
                }
            }

        } 
}

Thank you in advance

Pull the TRandom out of the loop, so it survives the generation of the first random number.

Ok it worked @StephanH thank you very much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.