The 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 base functions set.seed, RNGkind, runif, rnorm, and rexp.

dqrrademacher uses a fast algorithm to generate random Rademacher variables (-1 and 1 with equal probability). To do so, it generates a random 64 bit integer and then uses each bit to generate a 0/1 variable. This generates 64 integers per random number generation.

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 RNGkind


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


dqrunif, dqrnorm, and dqrexp return a numeric vector of length n. dqrrademacher returns an integer vector of length n.


Supported RNG kinds:


The default 64 bit variant from the PCG family developed by Melissa O'Neill. See for more details.

Xoroshiro128++ and Xoshiro256++

RNGs developed by David Blackman and Sebastiano Vigna. See for more details. The older generators Xoroshiro128+ and Xoshiro256+ should be used only for backwards compatibility.


The 64 bit version of the 20 rounds Threefry engine as provided by sitmo-package

Xoroshiro128++ is the default since it is fast, small and has good statistical properties.

The functions dqrnorm and dqrexp use the Ziggurat algorithm as provided by boost.random.

See 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 seed is NULL, a seed is generated from R's RNG without state alteration.

See also



# Set custom RNG.

# Use an integer scalar to set a seed.

# 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)
#> [1] 6.671009 6.819399 5.809120 7.420207 9.432123
dqrexp(5, rate = 4)
#> [1] 0.3195102 0.1255143 0.3573952 0.7278543 0.1367707
dqrnorm(5, mean = 5, sd = 3)
#> [1] 2.479324 2.667785 4.365715 7.538162 4.144456