random.distribution: Inverse transform sampling for random number generation

View source: R/distribution.R

random.distributionR Documentation

Inverse transform sampling for random number generation

Description

Generates random numbers from a distribution object by mapping uniform random variates through the target quantile function.

Usage

## S3 method for class 'distribution'
random(x, n = 1L, drop = TRUE, ...)

Arguments

x

An object of class distribution.

n

Number of observations. If length(n) > 1, the length is taken to be the number required.

drop

logical. Should the result be simplified to a vector if possible?

...

currently unused.

Value

A numeric vector of random values if length(d) equals one or n = 1L and drop = TRUE (default), or a matrix where rows correspond to the distribution(s) d whilst the columns contain the random values.

Examples

## Drawing random numbers from a Poisson distribution
## using the inverse transform sampling method
random.distribution(Poisson(3), n = 6)

## Drawing random numbers from a series of Normal distributions
## using the inverse transform sampling method
random.distribution(Normal(1:3, 1:3 / 2), n = 6)


distributions3 documentation built on Nov. 27, 2026, 5:07 p.m.