Thank you all for these answers.
If you try "rcpp random number generation" in a search engine,
the first line will point to
http://gallery.rcpp.org/articles/random-number-generation/
which probably has your answer.
Best,
Serguei
Yes of course i tried http://gallery.rcpp.org/articl
es/random-number-generation/, which helps to replace the rand function, and
effectively, i found the set.seed () (from R), just i didn't know how t use
it in C++.
-----------------------------------------------------------------
-----------------
In short, no.
Slightly longer: All Rcpp code is set up to be used _from R_ so by design
you
are always in R before you call code containing Rcpp. So just call the R
function set.seed(...) as we work hard to make sure the state is properly
set
and passed before and after.
Even longer: srand() is always wrong and bad (long literature on that ...)
and has nothing to do with R's RNG. You are entirely free to define and
implement your own RNG (see my RcppZiggurrat package revisiting Marsaglia's
Ziggurat RNG) or call others (C++11 has some) or ... But you probably want
to use R's RNGs, and for that you have to set them from R (or use
Rcpp::Function()). Also see the docs on the R Math Library (Section 6.16 of
Writing R Extensions) which gives you special functions and RNGs and even
set_seed() but that is for use _apart from R_ which is NOT what we do here.
Thx, I will look at RcppZiggurrat package, and also try other C++ functions.
-----------------------------------------------------------------
-----------------
Hi Youssef,
Rcpp has sugar for the R random number generators. This is nice if you want
to let your users set the random seed in R code outside of the package for
reproducibility: http://gallery.rcpp.org/articles/random-number-generation/
Alternatively, if you enable C++11, there are some random number generators
in std: https://www.guyrutenberg.com/2014/05/03/c-mt19937-example/
Best,
--
Hao Ye
Thx, in my case, i have it initialize the number generator, so i will try
check the proposed link.
-----------------------------------------------------------------
-----------------
Best regards,
Youssef
Post by Hao YeHi Youssef,
Rcpp has sugar for the R random number generators. This is nice if you
want to let your users set the random seed in R code outside of the package
for reproducibility: http://gallery.rcpp.org/articles/
random-number-generation/
Alternatively, if you enable C++11, there are some random number
generators in std: https://www.guyrutenberg.com/2014/05/03/c-mt19937-
example/
Best,
--
Hao Ye
On Wed, Feb 7, 2018 at 10:20 AM, Hmamouche Youssef <
Post by Hmamouche YoussefHi,
Found â_srandâ, possibly from âsrandâ
Found no calls to: âR_registerRoutinesâ, âR_useDynamicSymbolsâ
Is there some an equivalent function for srand from Rcpp, which i can
use it inside c++ code?
Best regards,
Youssef
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel