1 Goal


The goal of this tutorial is to unset the seed after it has been set in order to have random results again.


2 Set the seed


# We can set the seed using the set.seed function
for(i in 1:5){
  set.seed(123)
  print(sample(0:10,5))
}
## [1]  3  7 10  9  6
## [1]  3  7 10  9  6
## [1]  3  7 10  9  6
## [1]  3  7 10  9  6
## [1]  3  7 10  9  6

3 Unset the seed


# We can use the clock of the computer to set the seed to a random seed every time
set.seed(Sys.time())
for(i in 1:5){
  print(sample(0:10,5))
}
## [1]  4  7 10  5  0
## [1]  8  1  6  3 10
## [1] 5 3 9 2 8
## [1] 9 8 0 3 7
## [1]  9 10  3  4  8

4 Conclusion


In this tutorial we have learnt how to set the seed to a random seed every time we run the code by using the clock of the computer.