[Rcpp-devel] Mersenne Twister in RcppArmadillo?

Yan Zhou zhouyan at me.com
Sat Feb 9 15:32:45 CET 2013


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:

> Dear Rcpp-Devels,
> 
> I am right now working on a simulation where I use the 'randn()' function of Armadillo. I know, that the seed can be controlled via std::srand(). What I would like to know is: What kind of Generator is used by Armadillo? Can I in some way use the std::mt19937 or std::mt19937_64 random generator from the C++ random header? Actually this object is an instantiation of the mersenne_twister_engine, which is then for instance passed to the C++ 'shuffle()' function from the algorithm header. How to make Armadillo aware of the mersenne_twister_engine is something I haven't understood yet. 
> 
> Has anyone experience with this? 
> 
> 
> Best
> 
> Simon
> 
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



More information about the Rcpp-devel mailing list