Several fast random number generators are provided as C++
header only libraries: The PCG family by O'Neill (2014
< https://www.cs.hmc.edu/tr/hmc-cs-2014-0905.pdf>) as well as
Xoroshiro128+ and Xoshiro256+ by Blackman and Vigna (2018
The dqrng package provides fast random number generators (RNG) with good statistical properties for usage with R. It combines these RNGs with fast distribution functions to sample from uniform, normal or exponential distributions. Both the RNGs and the distribution functions are distributed as C++ header-only library.
The currently released version is available from CRAN via
Intermediate releases can also be obtained via drat:
if (!requireNamespace("drat", quietly = TRUE)) install.packages("drat")drat::addRepo("daqana")install.packages("dqrng")
Using the provided RNGs from R is deliberately similar to using R's build-in RNGs:
library(dqrng)dqRNGkind("Xoroshiro128+")dqset.seed(42)dqrunif(5, min = 2, max = 10)dqrexp(5, rate = 4)#>  0.5520084 0.1982174 0.3281557 0.1913137 0.7544450
They are quite a bit faster, though:
N <- 1e7system.time(rnorm(N))#> user system elapsed#> 0.756 0.000 0.757system.time(dqrnorm(N))#> user system elapsed#> 0.068 0.027 0.094
std::random_deviceas source of the default seed, since
std::random_deviceis deterministic with MinGW (c.f. #2)
dqrng_distribution.hcan now be used independently of Rcpp
xoshiro.h. This implementation is directly derived from the original C implementations. It provides v1.0 of Xoroshiro128+ and Xoshiro256+.