This generates random numbers from a zero-truncated Poisson distribution, i.e. from `X | X > 0` when `X ~ Poisson(lambda)`. The advantage here is that we guarantee to return exactly `n` numbers and without using a loop internally. This solution was provided in a post by [Peter Dalgaard](https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html).

rtpois(n, lambda)

Arguments

n

number of random numbers.

lambda

non-negative mean(s).

Value

The random numbers.

Examples

x <- rpois(1e6, lambda = 5)
x <- x[x > 0]
hist(x)


y <- rtpois(1e6, lambda = 5)
hist(y)