rnormlim: Generate Random Normal Numbers with Limits

View source: R/rnormlim.r

rnormlimR Documentation

Generate Random Normal Numbers with Limits

Description

Generates random numbers from a normal distribution with specified mean and standard deviation, constrained between minimum and maximum values. Any values outside the specified range are resampled until they fall within the limits.

Usage

rnormlim(n, mu = 0, sigma = 1, min = -Inf, max = Inf)

Arguments

n

Number of observations to generate

mu

Mean of the normal distribution (default = 0)

sigma

Standard deviation of the normal distribution (default = 1)

min

Minimum allowed value (default = -Inf)

max

Maximum allowed value (default = Inf)

Value

A numeric vector of length n containing random normal values constrained between min and max

Examples

# Generate 1000 standard normal values between -2 and 2
x <- rnormlim(1000, mu = 0, sigma = 1, min = -2, max = 2)

# Generate 500 normal values with mean 10, sd 2, minimum 5
y <- rnormlim(500, mu = 10, sigma = 2, min = 5)


ccamp83/mu documentation built on Nov. 7, 2024, 5:17 p.m.