Universal random number generator for MaCh3.
More...
#include <Manager/Random.h>
|
| void | SetSeed (const std::uint64_t seed) |
| | Set the global seed and initialise all RNG streams. More...
|
| |
| std::uint64_t | GetSeed () const |
| | Get the global seed. More...
|
| |
| TRandom3 * | Engine () |
| | Get the random generator associated with the current thread. More...
|
| |
| double | Uniform (const double min=0.0, const double max=1.0) |
| | Generate a uniform random number in [min, max). More...
|
| |
| int | UniformInt (const int min, const int max) |
| | Generate a uniform random integer in [min, max]. More...
|
| |
| double | Gaus (const double mean=0.0, const double sigma=1.0) |
| | Generate a Gaussian random number. More...
|
| |
| double | PoissonD (const double mean) |
| | Generate a double-precision Poisson-distributed random number with the given mean. More...
|
| |
| int | Poisson (const double mean) |
| | Generate an integer Poisson-distributed random number with the given mean. More...
|
| |
|
| std::uint64_t | fSeed = 0 |
| | The global seed. More...
|
| |
| std::vector< std::unique_ptr< TRandom3 > > | fEngines |
| | One random generator per thread. More...
|
| |
Universal random number generator for MaCh3.
- Note
- STL random-number generators were also benchmarked, but ROOT's TRandom3 was faster for the tested workloads. The implementation can be switched to an STL engine if needed.
- Author
- Kamil Skwarczynski
Definition at line 23 of file Random.h.
◆ Random()
| M3::rand::Random::Random |
( |
| ) |
|
|
inlineprivate |
Constructor.
Definition at line 90 of file Random.h.
void SetSeed(const std::uint64_t seed)
Set the global seed and initialise all RNG streams.
◆ Engine()
| TRandom3* M3::rand::Random::Engine |
( |
| ) |
|
|
inline |
Get the random generator associated with the current thread.
Definition at line 55 of file Random.h.
static std::size_t ThreadID()
Get the current OpenMP thread ID.
std::vector< std::unique_ptr< TRandom3 > > fEngines
One random generator per thread.
◆ Gaus()
| double M3::rand::Random::Gaus |
( |
const double |
mean = 0.0, |
|
|
const double |
sigma = 1.0 |
|
) |
| |
|
inline |
Generate a Gaussian random number.
Definition at line 71 of file Random.h.
73 return Engine()->Gaus(mean, sigma);
TRandom3 * Engine()
Get the random generator associated with the current thread.
◆ GetSeed()
| std::uint64_t M3::rand::Random::GetSeed |
( |
| ) |
const |
|
inline |
Get the global seed.
Definition at line 50 of file Random.h.
std::uint64_t fSeed
The global seed.
◆ Instance()
| static Random& M3::rand::Random::Instance |
( |
| ) |
|
|
inlinestatic |
◆ Poisson()
| int M3::rand::Random::Poisson |
( |
const double |
mean | ) |
|
|
inline |
Generate an integer Poisson-distributed random number with the given mean.
Definition at line 82 of file Random.h.
83 #pragma GCC diagnostic push
84 #pragma GCC diagnostic ignored "-Wconversion"
85 return Engine()->Poisson(mean);
86 #pragma GCC diagnostic pop
◆ PoissonD()
| double M3::rand::Random::PoissonD |
( |
const double |
mean | ) |
|
|
inline |
Generate a double-precision Poisson-distributed random number with the given mean.
Definition at line 77 of file Random.h.
78 return Engine()->PoissonD(mean);
◆ SetSeed()
| void M3::rand::Random::SetSeed |
( |
const std::uint64_t |
seed | ) |
|
|
inline |
Set the global seed and initialise all RNG streams.
This should be called once at the beginning of the executable, before any multithreaded work is started.
Definition at line 37 of file Random.h.
44 for (
int thread = 0; thread < nThreads; ++thread) {
int GetNThreads()
number of threads which we need for example for TRandom3
◆ ThreadID()
| static std::size_t M3::rand::Random::ThreadID |
( |
| ) |
|
|
inlinestaticprivate |
Get the current OpenMP thread ID.
Definition at line 95 of file Random.h.
97 return static_cast<std::size_t
>(omp_get_thread_num());
◆ Uniform()
| double M3::rand::Random::Uniform |
( |
const double |
min = 0.0, |
|
|
const double |
max = 1.0 |
|
) |
| |
|
inline |
Generate a uniform random number in [min, max).
Definition at line 60 of file Random.h.
62 return Engine()->Uniform(min, max);
◆ UniformInt()
| int M3::rand::Random::UniformInt |
( |
const int |
min, |
|
|
const int |
max |
|
) |
| |
|
inline |
Generate a uniform random integer in [min, max].
Definition at line 66 of file Random.h.
67 return Engine()->Integer(max - min + 1) + min;
◆ fEngines
| std::vector<std::unique_ptr<TRandom3> > M3::rand::Random::fEngines |
|
private |
One random generator per thread.
Definition at line 107 of file Random.h.
◆ fSeed
| std::uint64_t M3::rand::Random::fSeed = 0 |
|
private |
The global seed.
Definition at line 104 of file Random.h.
The documentation for this class was generated from the following file: