rpgm.rnorm: Fast Simulation of Normal Random Variables

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/rpgm.rnorm.R

Description

The function rpgm.rnorm uses the Ziggurat algorithm with a 128-regions table, in order to simulate normal random variables faster than rnorm.

Usage

1
rpgm.rnorm(n, mean = 0, sd = 1, nthreads = 1L)

Arguments

n

integer, number of simulations.

mean

double, the mean (or the vector of means).

sd

double, the standard deviation (or the vector of standard deviations).

nthreads

integer, the number of threads to use for parallelism.

Details

If mean or sd are not specified they assume the default values of 0 and 1, respectively. By default the number of threads is 1 so there is no multi-core.

Value

A vector of i.i.d. normal random variables.

Note

For a big number of simulations, with nthreads = 1, it is approximately four times faster than the usual rnorm. For one simulution, it is around one half faster.

Author(s)

Nicolas Baradel - PGM Solutions

References

https://en.wikipedia.org/wiki/Ziggurat_algorithm

See Also

http://pgm-solutions.com/packages

Examples

1
2
rpgm.rnorm(5)
rpgm.rnorm(5, nthreads = maxthreads())

rpgm documentation built on March 18, 2018, 2:24 p.m.