gpt4 book ai didi

c++ - 使用用户定义的随机生成器运行 std::normal_distribution

转载 作者:搜寻专家 更新时间:2023-10-31 00:15:32 25 4
gpt4 key购买 nike

我要生成一组正态分布的伪随机数。据我所知,std 库为此提供了以下代码:

std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<> d(mean,std);
...
double number = d(gen);

问题是我想使用 Sobol 的准随机序列而不是 MersenneTwister 伪随机生成器。所以,我的问题是:是否可以使用用户定义的随机生成器(在我的例子中使用 Sobol 的准随机序列生成器)来运行 std::normal_distribution?


更多细节:我有一个名为 RandomGenerators 的类,用于生成 Sobol 的准随机数:

RandomGenerator randgen;
double number = randgen.sobol(0,1);

最佳答案

是的,这是可能的。只需使其符合统一随机数生成器的要求即可(§26.5.1.3 第 2 和第 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().

关于c++ - 使用用户定义的随机生成器运行 std::normal_distribution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19178647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com