-
Notifications
You must be signed in to change notification settings - Fork 76
/
seed.qmd
19 lines (11 loc) · 921 Bytes
/
seed.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Setting the seed
* `set.seed()`
Computers in general, and R specifically, can, in fact, only provide *pseudo*random number generators.
A pseudorandom number generator's number sequence is completely determined by its seed, i.e. a number used to initialize that sequence.
Thus, if a pseudorandom number generator is reinitialized with the same seed, it will produce the same sequence of numbers.
You can set the seed (with any arbitrary number) at the beginning of a script, and, if commands drawing random numbers are run in the exact same order, they will provide the same output in subsequent runs.
This is useful for sharing code and reproduce simulations, as well as for debugging code.
***
**YOUR TURN:**
In your local exercise script, play around with the function `set.seed()` by running and modifying the examples provided (e.g. compare outputs with and without seeds, change the seed number).
***