I had a few questions about generating random numbers from TF1s in ROOT.
First, there look to be two ways to generate these numbers. One can define a TF1 and call TF1::GetRandom() or instantiate a TUnuran object with TF1. Is there a speed benefit to either method (or does TF1::GetRandom() use TUnuran deep down)?
Secondly, if I don’t provide bounds on the TF1 it seems to automatically set the bounds to (0, 1) which means TF1::GetRandom() is limited to (0, 1). Is there a way to set the bounds to +/- infinity without using an arbitrarily large numbers for bounds?
TF1::GetRandom() is an approximate method and works for a bounded region. You can tune by using TF1::SetNpx() to increase the number of points used, but you will decrease the efficiency
Unuran instead provide exact methods, which work for both limited and unlimited distributions and they can be in some cases even more efficient.
Addendum to Lorenzo’s answer:
You can specify the function range in the TF1 constructor. By default GetRandom will return a number in the specified range.
Many thanks. Exactly the kind of information for which I was looking.
Rene,
I’m aware of the constructor options, but I would effectively like to set them to -infinity and infinity. Is this possible without using arbitrary large numbers?
Also, do the bounds of the TF1 extend to Unuran when TUnuran::Init(TUnuranDistrCont(TF1 f)) is used?
Apologies for one more question. I’m trying to use TUnuran for sampling in compiled code. I have no problems with TUnuran itself, but I can’t seem to find the appropriate header for TUnuranDistrCont.
I have a fink install on Mac OS X 10.4, and all I can find is TUnuranDistr.h which doesn’t seem to help. Any help would be appreciated.