rlnorm_trng: Log-normal random numbers via TRNG.

View source: R/rlnorm_trng.R

rlnorm_trngR Documentation

Log-normal random numbers via TRNG.


Random number generation for the log-normal distribution using the TRNG C++ library.


rlnorm_trng(n, meanlog = 0, sdlog = 1, engine = NULL, parallelGrain = 0L)



Number of observations.

meanlog, sdlog

Parameters of the distribution, with the same meaning as in rlnorm. Note however that only scalar values are accepted.


Optional TRNG engine object; if missing or NULL, the current engine controlled via TRNG.Random is used.


Optional argument controlling the parallel simulation of random variates (see ‘Parallel Simulation’ below for details).


Numeric vector of random variates generated with the given parameters. The length is determined by n.

Parallel Simulation

When a positive value of argument parallelGrain is supplied, random variates are simulated in parallel, provided a parallel random number engine is selected. This is done using RcppParallel via parallelFor, which uses the supplied parallelGrain to control the grain size (the number of threads being controlled by setThreadOptions). The grain size can greatly affect the overhead of performing the required block splitting jump operations and should be selected carefully. Note that TRNG guarantees the outcome of such parallel execution to be equivalent to a purely sequential simulation.

See Also

rlnorm, TRNG.Engine, TRNG.Random.

Other TRNG distributions: rbinom_trng(), rnorm_trng(), rpois_trng(), runif_trng()


## generate 10 random variates using the current TRNG engine
rlnorm_trng(10, meanlog = 0, sdlog = 1)

## use a TRNG engine reference class object
r <- yarn2$new()
rlnorm_trng(10, meanlog = 0, sdlog = 1, engine = r)

## generate 100k random variates in parallel, with 2 threads and 100 grain size
RcppParallel::setThreadOptions(numThreads = 2L)
x_parallel <- rlnorm_trng(100e3, meanlog = 0, sdlog = 1, parallelGrain = 100L)
x_serial <- rlnorm_trng(100e3, meanlog = 0, sdlog = 1)
identical(x_serial, x_parallel)

rTRNG documentation built on March 18, 2022, 7:15 p.m.