Generate random numbers from a uniform distribution.
The runif() function generates random deviates from a uniform distribution on the interval [min, max]. By default, it generates from the standard uniform distribution on [0, 1].
runif is commonly used for simulations, random sampling, and generating test data. For reproducible results, set the random seed with set.seed() before calling runif.
| Name | Description | Optional |
|---|---|---|
n |
Number of random values to generate. | No |
min |
Lower limit of the distribution. Defaults to 0. | Yes |
max |
Upper limit of the distribution. Defaults to 1. | Yes |
runif(5) # 5 values in [0, 1]
runif(3, min = 1, max = 10) # 3 values in [1, 10]
floor(runif(5, 1, 7)) # 5 random dice rolls