R Under development (unstable) (2024-10-17 r87242 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(randtoolbox) Loading required package: rngWELL This is randtoolbox. For an overview, type 'help("randtoolbox")'. > RNGkind() [1] "Mersenne-Twister" "Inversion" "Rejection" > > n <- 10 > > #set WELL19937a > set.generator("WELL", version="19937a", seed=12345) > runif(n) [1] 0.96877622 0.93477110 0.64725061 0.82920786 0.56494618 0.87516860 [7] 0.59501939 0.54398493 0.98080228 0.04542682 > > > storedState <- get.description() > x <- runif(n) > > y <- runif(n) > > #Restore the generator from storedState and regenerate the same numbers > put.description(storedState) > all(x == runif(n)) [1] TRUE > > > # generate the same random numbers as in Matlab > set.generator("MersenneTwister", initialization="init2002", resolution=53, seed=12345) > runif(n) [1] 0.9296161 0.3163756 0.1839188 0.2045603 0.5677250 0.5955447 0.9645145 [8] 0.6531771 0.7489066 0.6535699 > # [1] 0.9296161 0.3163756 0.1839188 0.2045603 0.5677250 > # Matlab commands rand('twister', 12345); rand(1, 5) generate the same numbers, > # which in short format are 0.9296 0.3164 0.1839 0.2046 0.5677 > > > storedState <- get.description() > > proc.time() user system elapsed 0.12 0.10 0.21