Question on set.seed

We use set.seed(integer) to get a reproducible sequence of (pseudo) random numbers. My question is how often within an R program does set.seed need to be used? If I use it in line 1, does it remain in use for the entire program? Or does it need to be reset each time I am using random numbers.

Thank you.

once in session is sufficient, but I suppose exposes you to human error as if you are working interactively you should be careful not to run twice any random generating element, because when you reopen the script and run again, you will only get matching results if you reran the offending code segment twice also which you wont if the script runs end to end. setting seed before each random generating code will reduce this error likelihood at the cost of additional text in your script

in my own work I try to get the best of both worlds by only setting seed once, for nicer cleaner code.
but would always rerun my workflow end to end, before recording my results and consider that final clean run to be the reproducible once, and any previously partially run interactive results are consigned to the trashbin of history

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