Pulls out random numbers that follow the bell-shaped pattern.
rnorm(n, mean = 0, sd = 1)
Key idea
rnorm draws n random numbers from a normal distribution with a given mean (centre) and sd (spread). (e.g. rnorm(5, 180, 10))
Each run gives different numbers because the draws are random.
Setting a seed first — a fixed starting number — makes the same random values appear every time.
With many draws, the average of your sample lands close to the true mean. (e.g. n = 1000 -> mean ~ 180)
It is useful for simulations and for seeing how randomness behaves.
Definition
X1,…,Xn∼iidN(μ,σ2)
n
how many values to draw
μ
the mean
σ
the standard deviation
N(μ,σ2)
a normal distribution
Xi∼N(180,102)⇒xˉ≈180,s≈10
In plain words
Like a bag full of heights that bunch up around the middle. You reach in and grab n of them without looking. The seed — a starting number — makes sure you grab the same ones each time, so the result can be repeated.
Where you'd use it
You want a pretend class of 30 test scores to practise on. rnorm(30, 75, 8) invents 30 numbers centred near 75, most landing between about 59 and 91, so you get realistic-looking scores without any real data.
To model tiny measurement errors in an experiment, draw noise with rnorm(100, 0, 0.5). You get 100 small wobbles averaging near 0, mimicking the random slip in each reading.
Generate 200 fake heights with rnorm(200, 170, 7) to test other functions; their average comes out close to 170 cm, and using the same seed lets a friend reproduce the exact same 200 numbers.
Frequently asked questions
Why do I get different numbers every run?
rnorm draws random samples. Call set.seed(n) first to make them reproducible.
How do I set the centre and spread?
rnorm(n, mean, sd) — the 2nd/3rd args. sd is the standard deviation, not the variance.