Generating random numbers
Generating random numbers
If you just need to generate basic random numbers in R, you can use the following simple
methods:
3. Random Integers
R
Копировать код
sample(min:max, size, replace = TRUE)
Every time you run this code with the same seed, you will get the same random numbers.
—--------------------------------------------------------------------------------------------------------
Syntax
R
Копировать код
rnorm(n, mean = 0, sd = 1)
Arguments
Return Value
A numeric vector of length n containing random numbers sampled from the specified normal
distribution.
Example Usage
Generate 10 random numbers from a standard normal distribution (mean = 0, sd = 1):
R
Копировать код
rnorm(10)
1.
2.
3.
—----------------------------------------------------------------------------------------------
Uniform Distribution
Normal Distribution