set.seed doesnt work

does anybody have an idea, why the results are differing? Couldnt find a solution on the internet
I`m using R version 4.1.2 (2021-11-01).

> set.seed(2021)
> rnorm(5)
[1] -0.1224600  0.5524566  0.3486495  0.3596322  0.8980537
> rnorm(5)
[1] -1.92256952  0.26174436  0.91556637  0.01377194  1.72996316
> rnorm(5)
[1] -1.0822049 -0.2728252  0.1819954  1.5085418  1.6044701
> rnorm(5)
[1] -1.841476  1.623310  0.131389  1.481122  1.513318
> rnorm(5)
[1] -0.9424433 -0.1856850 -1.1011246  1.2081153 -1.6249385

thanks for your help in advance,
Joe

It does work. You're just not using in the way it's expected.

If you set a particular seed and run some function with randomness, any repetition will be reproducible. But if you call the function multiple times after setting seed once, it'll vary.

Try this, and let us know if it shows different results or same:

set.seed(2021)
rnorm(5)
set.seed(2021)
rnorm(5)
set.seed(2021)
rnorm(5)
set.seed(2021)
rnorm(5)
set.seed(2021)
rnorm(5)
1 Like

it works this way. Thank you very much!!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.