Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running std::normal_distribution with user-defined random generator

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);
like image 288
Dinar Abdullin Avatar asked Feb 01 '26 21:02

Dinar Abdullin


1 Answers

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 G satisfies the requirements of a uniform random number generator if the expressions shown in Table 116 are valid and have the indicated semantics, and if G also satisfies all other requirements of this section. In that Table and throughout this section:

a) T is the type named by G’s associatedresult_type`, and

b) g is a value of G.

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().

like image 109
R. Martinho Fernandes Avatar answered Feb 04 '26 11:02

R. Martinho Fernandes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!