Armadillo 使用的随机数生成器是什么?

What is the random number generator that Armadillo uses?

我正在使用 R 的 Armadillo C++ 库中的随机数生成器。Armadillo 允许对矩阵和向量进行高性能计算。但是,我看不到它实际实现的是哪个随机数生成器。

Rcpp Armadillo 使用的随机数生成器到底是什么?

Depending on whether RcppArmadillo was compiled for the C++98 standard (currently the default) or for C++11 (optional), two different RNGs may be used. [...] For C++98, the system library RNG is used. It may have poor performance, particularly on older versions of Windows. For C++11, the RNG included in its library is used. - RcppArmadillo Documentation

"For C++98, the system library RNG is used." - 系统库 RNG 是 std::rand(),尽管 RcppArmadillo 似乎使用 R 中的 RNG 作为后备(当 C+ +11 未被选中,因此基于 C++11 的 RNG 不可用),这避免了使用旧的基于 C++98 的 std::rand().1

"For C++11, the RNG included in its library is used." - 这是指 C++11 <random> 库。

另一方面,还要考虑this comment in RcppArmadilloForward.h:

// using this define makes the R RNG have precedent over both the
// C++11-based RNG provided by Armadillo, as well as the C++98-based
// fallback.
//
// One can use the C++11-based on by commenting out the following
// #define and also selecting C++11 (eg via src/Makevars* or the
// DESCRIPTION file) and/or defining #define-ing ARMA_USE_CXX11_RNG
#define ARMA_RNG_ALT         RcppArmadillo/Alt_R_RNG.h

它打开 R RNG 作为 RcppArmadillo 的引擎。


1 R-bloggers | RcppArmadillo 0.4.450.1.0