Skip to content
Prev 5249 / 10988 Next

[Rcpp-devel] Mersenne Twister in RcppArmadillo?

You have at least two choices.

1. Just use std::mt19937 as you do in other C++ code.
std::mt19937 eng;
std::normal_distribuiton rnorm(0, 10); // or any other dist you need
arma::vec v(N);
for (int i = 0; i != N; ++i)
	v[i] = rnorm(eng);

2. Rcpp has convenient way to use R runtime's RNG, which I believe by default is Mersenne Twister. See doc of Rcpp sugar. Also you can access Rmath directly.

To have Armadillo randn use MT19937 is not easy. Since it use srand() for seed, I guess it also use C rand(), whose quality is quite questionable. 

Best

Yan Zhou
On Feb 9, 2013, at 2:24 PM, Simon Zehnder <szehnder at uni-bonn.de> wrote: