I am about to generate an array of normally distributed pseudo-random numbers. As I know the std library offers the following code for that:
std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<> d(mean,std);
...
double number = d(gen);
The problem is that I want to use a Sobol' quasi-random sequence instead of Mersenne Twister pseudo-random generator. So, my question is: Is it possible to run the std::normal_distribution with a user-defined random generator (with a Sobol' quasi-random sequence generator in my case)?
More details: I have a class called RandomGenerators, which is used to generate a Sobol' quasi-random numbers:
RandomGenerator randgen;
double number = randgen.sobol(0,1);
Yes, it is possible. Just make it comply to the requirements of a uniform random number generator (§26.5.1.3 paragraphs 2 and 3):
2 A class
Gsatisfies the requirements of a uniform random number generator if the expressions shown in Table 116 are valid and have the indicated semantics, and ifGalso satisfies all other requirements of this section. In that Table and throughout this section:a)
Tis the type named byG’s associatedresult_type`, andb)
gis a value ofG.Table 116 — Uniform random number generator requirements
Expression | Return type | Pre/post-condition | Complexity ---------------------------------------------------------------------- G::result_type | T | T is an unsigned integer | compile-time | | type (§3.9.1). | ---------------------------------------------------------------------- g() | T | Returns a value in the | amortized constant | | closed interval | | | [G::min(), G::max()]. | ---------------------------------------------------------------------- G::min() | T | Denotes the least value | compile-time | | potentially returned by | | | operator(). | ---------------------------------------------------------------------- G::max() | T | Denotes the greatest value | compile-time | | potentially returned by | | | operator(). |3 The following relation shall hold:
G::min() < G::max().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With