Random sampling is useful, but examples and tests need repeatable output. set.seed fixes the random sequence.

Program

Play the script to see the same sample produce the same total every run.

set_seed.R
set.seed(7)
draws <- sample(1:10, 3)
total <- sum(draws)
cat(total, "\n", sep = "")
set.seed `set.seed(7)` makes later random operations repeatable.
sample `sample(1:10, 3)` chooses three values.
reproducibility A fixed seed helps examples and tests produce stable results.