GetRandom in specific histogram range

Is it possible to specify the axis range over which I want the TH1::GetRandom to work? (also interested in TH3::GetRandom3D)

For example:

TH1F* h = new TH1F("h", "", 100, -10, 10);
h->FillRandom("gaus", 100000);
h->GetXaxis()->SetRange(0, 50); //x axis from -10 to 0
Float_t myRandom = h->GetRandom(); //this number can be outside the above-specified range

Ultimately I actually want to do this with a TH3: I want to specify the x-value and get a random y-z pair without having to do a y-z projection every time. Is this possible?
One alternative is generating a myriad TH2’s, one for each x-bin… but I was trying to avoid that if possible.

Thanks in advance!

ROOT Version: 6.10/06
Platform, compiler: x86_64-slc6-gcc62-opt

It does not seems GetRandom takes the Range into account. @moneta can confirm ?

1 Like

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