[Rcpp-devel] Mersenne Twister in RcppArmadillo?

Simon Zehnder szehnder at uni-bonn.de
Sun Feb 10 10:33:03 CET 2013

Actually I arrived at another fundamental question: 

I read '6.3 Random Number Generation' in the R Extensions Guide. It seems that it is not possible to set out of C++ the random seed (the wrapper RNGScope calls GetRNGstate() and PutRNGState() so it should have no extended functionality), which is very important when trying to produce reproducible results. So, I need a Mersenne-Twister, but I must be able to set the seed in every iteration. I think this brings me to the GSL library or - as long only normal random variates are needed - to the C++ std::random header?

Best Simon

On Feb 9, 2013, at 5:42 PM, Yan Zhou <zhouyan at me.com> wrote:

>> This really is a BIG topic and worth a few more comments. Note that I wrote a
>> few related posts on RNGs at the Rcpp Gallery, see for example
>> http://gallery.rcpp.org/articles/timing-normal-rngs/
>> which compares the RNGs from R, C++11 and Boost. Simon just added Armadillo to
>> the list, we can add even more RNGs fromn other packages.
> If it is of interest to anyone, I once timed Boost, C++11 and Random123 (A high performance parallel RNG, http://www.thesalmons.org/john/random123/releases/latest/docs/, It come with a C++11 compatible RNG engine, can be used just like std::mt19937) once for different compilers on Linux. I just uploaded them to https://github.com/zhouyan/vSMC/wiki/RNG-performance-comparison
> There are two benchmark, one for the performance of URNG (mt19937 etc). These include those in C++11 <random> and Boost.Random, which are almost identical in functionality (C++11 <random> is based on Boost.Random after all). Also they include two URNG from Random123, threefry and philox (both come with four basic configurations)
> Another benchmark is the performance of generating distribution random numbers (such as normal). The Random123 threefry2x64 was used for all distribution and compilers, since it is the one with least performance difference between compilers.
> Compilers include,
> clang SVN with libstdc++ 4.7
> clang SVN with libc++ SVN
> gcc 4.7
> intel icpc 13
> clang and gcc version also come with results when using AMD libm instead of glibc. However, the benchmark are not Rcpp specific. They are compiled to standalone C++ programs. But all these URNGs can be used Rcpp. As demonstrated in Dirk's example. 
> Best,
> Yan Zhou

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130210/57b2db9b/attachment.html>

More information about the Rcpp-devel mailing list