Hello
Problem: related to the generation of large amount of random numbers using TRandom3.
Example code:
A global TRandom3 object is used for generating random numbers.
This code will generate nEntries “uniformly random” numbers, between 0 and 1, with double precision. They will be stored in a std::map (they will be sorted).
Check of randomness: if the random numbers are uniform, the difference between the following and the previous number should follow an exponential function, with slope the number of elements (for this case).
#include<map>
#include "TRandom3.h"
#include "TH1D.h"
std::map < double , double > aMap;
TRandom3 r;
TH1D* h;
void mapProblem(std::size_t nEntries = 1e8 )
{
for( std::size_t counter = 0; counter< nEntries; ++counter )
{
aMap.emplace( r.Uniform(0,1), counter);
}
h= new TH1D("h","",1000,0,10./nEntries);
double last = 0;
for( auto mit:aMap )
{
if( last )
h->Fill( mit.first - last );
last = mit.first;
}
return;
}
Output:
-> For nEntries = 1e5 everything looks ok, as you can see in the attached file mapProblemTH1D_1e5.root mapProblemTH1D_1e5.root (27.3 KB)
-> But for nEntries = 1e8 (it will take few minutes, and several GB of RAM memory), empty bins appear*. as you can see in the attached file mapProblemTH1D_1e8.root. mapProblemTH1D_1e8.root (28.0 KB)
If the histogram is rebined,
h->Rebin(5)
a structure appears superimposed over the exponential. The empty bins (*) are not equally spaced, so they may be the origin of this structure.
Please, correct me if I’m wrong: 1% of the random numbers are not inserted in the std::map because they are repeated (lack of precision?); I don’t know the origin of empty bins.
Question: May TRandom3 random numbers be affected by a kind of correlation between them//repetition effect, or it’s just the randomness check which is failing? (I don’t know any test for random numbers)
Thank you for your time.
Regards,
atd