dqrng package provides several fast random number
generators together with fast functions for generating random numbers
according to a uniform, normal and exponential distribution. These
functions are modeled after the
dqRNGkind(kind, normal_kind = "ignored") dqrunif(n, min = 0, max = 1) dqrnorm(n, mean = 0, sd = 1) dqrexp(n, rate = 1) dqset.seed(seed, stream = NULL)
string specifying the RNG (see details)
ignored; included for compatibility with
number of observations
lower limit of the uniform distribution
upper limit of the uniform distribution
mean value of the normal distribution
standard deviation of the normal distribution
rate of the exponential distribution
integer scalar to seed the random number generator, or an integer vector of length 2 representing a 64-bit seed. Maybe
NULL, see details.
integer used for selecting the RNG stream; either a scalar or a vector of length 2
dqrexp return a numeric vector of length
Supported RNG kinds:
The default 64 bit variant from the PCG family developed by Melissa O'Neill. See https://www.pcg-random.org/ for more details.
RNGs developed by David Blackman and Sebastiano Vigna. They are used as default RNGs in Erlang and Lua. See https://xoshiro.di.unimi.it/ for more details.
The 64 bit version of the 20 rounds Threefry engine as
Xoroshiro128+ is the default since it is the fastest generator provided by this package.
dqrexp use the Ziggurat algorithm as
generateSeedVectors for rapid generation of integer-vector
seeds that provide 64 bits of entropy. These allow full exploration of
the state space of the 64-bit RNGs provided in this package.
If the provided
NULL, a seed is genenrated from R's RNG
without state alteration.
library(dqrng) # Set custom RNG. dqRNGkind("Xoshiro256+") # Use an integer scalar to set a seed. dqset.seed(42) # Use integer scalars to set a seed and the stream. dqset.seed(42, 123) # Use an integer vector to set a seed. dqset.seed(c(31311L, 24123423L)) # Use an integer vector to set a seed and a scalar to select the stream. dqset.seed(c(31311L, 24123423L), 123) # Random sampling from distributions. dqrunif(5, min = 2, max = 10) #>  9.254756 2.169924 3.232695 8.859045 4.940842 dqrexp(5, rate = 4) #>  0.003025477 0.213876337 0.008051277 0.399246137 0.066848602 dqrnorm(5, mean = 5, sd = 3) #>  1.399092 7.411358 7.145729 2.308440 6.766659