Skip to content

Instantly share code, notes, and snippets.

@Shusei-E
Last active May 8, 2023 18:50
Show Gist options
  • Save Shusei-E/d3ac99579f59371fd81d5c060d323479 to your computer and use it in GitHub Desktop.
Save Shusei-E/d3ac99579f59371fd81d5c060d323479 to your computer and use it in GitHub Desktop.
R: Saving Random State
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