What is the random number generator that Armadillo uses?

1.3k views Asked by At

I am using the random number generator from the Armadillo C++ library from R. Armadillo allows high-perfomance computation of matrices and vectors. However, I can't see which random number generator it is actually implementing.

What is the random number generator that Rcpp Armadillo uses exactly?

1

There are 1 answers

2
Jonny Henly On BEST ANSWER

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." - The system library RNG is std::rand(), although it seems as though RcppArmadillo uses the RNG from R as a fallback (when C++11 is not selected so the C++11-based RNG is unavailable) which avoids using the older C++98-based std::rand().1

"For C++11, the RNG included in its library is used." - This is referring to the C++11 <random> library.

On the other hand, also consider 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

which turns on the R RNGs as an engine for RcppArmadillo.


1 R-bloggers | RcppArmadillo 0.4.450.1.0