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] 3 6 0 8 5
## [1] 4 3 5 0 1
## [1] 1 7 0 8 5
## [1] 3 8 7 0 4
## [1] 10  7  2  5  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.