Skip to content

Instantly share code, notes, and snippets.

@mpjdem
Created December 27, 2019 11:33
Show Gist options
  • Save mpjdem/16eda9297e452628c285b37d71d2cc82 to your computer and use it in GitHub Desktop.
Save mpjdem/16eda9297e452628c285b37d71d2cc82 to your computer and use it in GitHub Desktop.
Example of global RNG state
pick_name <- function() {
names <- c("Dax", "Wug", "Lep", "Sik", "Bop")
sample(names)[1]
}
set.seed(100)
print(pick_name()) # Wug
print(runif(1)) # 0.4837707
pick_name <- function() {
names <- c("Dax", "Wug", "Lep", "Sik", "Bop")
sample(names, size = 1)
}
set.seed(100)
print(pick_name()) # Wug
print(runif(1)) # 0.2576725
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment