Learn R Programming

dqrng (version 0.0.3)

dqrng: Fast Pseudo Random Number Generators for R

Description

The dqrng package provides several fast random number generators as C++ header only libraries. In addition fast functions for generating random numbers according to a uniform, normal and exponential distribution are provided. These functions are exported to R and as a C++ interface and are modeled after the base functions set.seed, RNGkind, runif, rnorm, and rexp.

Usage

dqRNGkind(kind, normal_kind = "ignored")

dqrunif(n, min = 0, max = 1)

dqrnorm(n, mean = 0, sd = 1)

dqrexp(n, rate = 1)

dqset.seed(seed)

Arguments

kind

string specifying the RNG (see details)

normal_kind

ignored; included for compatibility with RNGkind

n

number of observations

min

lower limit of the uniform distribution

max

upper limit of the uniform distribution

mean

mean value of the normal distribution

sd

standard deviation of the normal distribution

rate

rate of the exponential distribution

seed

integer seed for the random number generator

Value

dqrunif, dqrnorm, and dqrexp return a numeric vector of length n.

Details

Supported RNG kinds:

Mersenne-Twister

The 64 bit variant of the well-known Mersenne-Twister, which is also used as default. This is a conservative default that allows you to take advantage of the fast distribution functions provided by dqrng while staying close to R's default RNG (32 bit Mersenne-Twister).

pcg64

The default 64 bit variant from the PCG family developed by Melissa O'Neill. See http://www.pcg-random.org for more details.

Xoroshiro128+ and Xoshiro256+

RNGs developed by David Blackman and Sebastiano Vigna. They are used as default RNGs in Erlang and Lua. See http://xoshiro.di.unimi.it/ for more details.

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

See Also

set.seed, RNGkind, runif, rnorm, and rexp

Examples

Run this code
# NOT RUN {
library(dqrng)
dqRNGkind("Xoroshiro128+")
dqset.seed(42)
dqrunif(5, min = 2, max = 10)
dqrexp(5, rate = 4)
dqrnorm(5, mean = 5, sd = 3)
# }

Run the code above in your browser using DataLab