Last active
May 8, 2023 18:50
-
-
Save Shusei-E/d3ac99579f59371fd81d5c060d323479 to your computer and use it in GitHub Desktop.
R: Saving Random State
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(225) | |
rnorm(5) | |
rnorm(5) | |
rnorm(5) | |
rand_state <- .GlobalEnv$.Random.seed | |
saveRDS(list(rand_state = rand_state), "rand_state.rds") | |
rnorm(5) # [1] 0.55203151 0.08414507 1.92445918 -0.65374544 1.42059484 | |
.GlobalEnv$.Random.seed <- readRDS("rand_state.rds")$rand_state | |
rnorm(5) # [1] 0.55203151 0.08414507 1.92445918 -0.65374544 1.42059484 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment