Fast Pseudo Random Number Generators

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 ). In addition fast functions for generating random numbers according to a uniform, normal and exponential distribution are included. The latter two use the Ziggurat algorithm originally proposed by Marsaglia and Tsang (2000, ). These functions are exported to R and as a C++ interface and are enabled for use with the 64 bit version of the Mersenne-Twister by Matsumoto and Nishimura (1998 ), the default 64 bit generator from the PCG family, Xoroshiro128+ and Xoshiro256+ as well as the 64 bit version of the 20 rounds Threefry engine (Salmon et al., 2011 ) as provided by the package 'sitmo'.


Travis build status AppVeyor build status CRAN status Coverage status Downloads

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.

Installation

The currently released version is available from CRAN via

install.packages("dqrng")

Intermediate releases can also be obtained via drat:

if (!requireNamespace("drat", quietly = TRUE)) install.packages("drat")
drat::addRepo("daqana")
install.packages("dqrng")

Example

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)
#> [1] 0.5520084 0.1982174 0.3281557 0.1913137 0.7544450

They are quite a bit faster, though:

N <- 1e7
system.time(rnorm(N))
#>    user  system elapsed 
#>   0.756   0.000   0.757
system.time(dqrnorm(N))
#>    user  system elapsed 
#>   0.068   0.027   0.094

News

dqrng 0.0.4

  • Fix critical bug w.r.t. setting seeds
  • Use time in addition to std::random_device as source of the default seed, since std::random_device is deterministic with MinGW (c.f. #2)
  • Add jump() method to Xoshiro256+ and Xorohiro128+
  • New vignette on parallel usage

dqrng 0.0.3

  • PCG has been patched to compile on Solaris.

dqrng 0.0.2

  • dqrng_distribution.h can now be used independently of Rcpp
  • Replace xorshift.hpp and xoroshiro.hpp with xoshiro.h. This implementation is directly derived from the original C implementations. It provides v1.0 of Xoroshiro128+ and Xoshiro256+.

dqrng 0.0.1

  • First public release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dqrng")

0.0.5 by Ralf Stubner, 15 days ago


https://www.daqana.org/dqrng, https://github.com/daqana/dqrng


Report a bug at https://github.com/daqana/dqrng/issues


Browse source code at https://github.com/cran/dqrng


Authors: Ralf Stubner [aut, cre] , daqana GmbH [cph] , David Blackman [ctb] , Melissa O'Neill [ctb] , Sebastiano Vigna [ctb]


Documentation:   PDF Manual  


Task views: High-Performance and Parallel Computing with R


AGPL-3 | file LICENSE license


Imports Rcpp

Suggests testthat, knitr, rmarkdown

Linking to Rcpp, BH, sitmo


See at CRAN