[Rcpp-devel] Setting the R random seed from Rcpp

Romain Francois romain at r-enthusiasts.com
Fri Jun 7 16:42:24 CEST 2013


You can do something like this (i'm on my phone, so you might have to change it): 

Environment g = Environment::global_env() ; 
Environment::Binding RandomSeed = g[".Random.seed"] ;

You get the current value of the binding like this: 

NumericVector someVariable = RandomSeed ;

And then when you want to set the variable: you just do :

RandomSeed = someVariable ; 

The Environment::Binding class acts a a proxy class. 

Romain


Le 7 juin 2013 à 16:22, Matteo Fasiolo <matteo.fasiolo at gmail.com> a écrit :

> Dear Rcpp experts,
> 
>  I would like to be able to store the R random seed from a Rcpp
> function and then reset it. In other words I would like to replicate
> the following code in Rcpp:
> 
> savedSeed <- .Random.seed
> x <- Rfunction(parameters1);
>       
> .Random.seed <- savedSeed
> x1 <- Rfunction(parameters2); 
> 
> where Rfunction simulates some random numbers and uses them
> but with different parameter values.
> Is it possible to do something similar in Rcpp?
> Probably using GetRNGstate() and PutRNGstate()?
> 
> Thanks,
> 
> Matteo
> _______________________________________________
> 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