Created
December 27, 2019 07:02
-
-
Save djnavarro/c992f93681f9b13141101d8a802ff53c to your computer and use it in GitHub Desktop.
The joy of coding when the RNG state is global...
This file contains 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
# someone else's package includes this inefficient function | |
pick_name <- function() { | |
names <- c("Dax", "Wug", "Lep", "Sik", "Bop") | |
sample(names)[1] | |
} | |
# here is my code that calls it... | |
set.seed(100) | |
print("--- Attempt 1 ---") | |
print(pick_name()) # Wug | |
print(pick_name()) # Dax | |
print(pick_name()) # Sik | |
# it is reproducible... | |
set.seed(100) | |
print("--- Attempt 2 ---") | |
print(pick_name()) # Wug | |
print(pick_name()) # Dax | |
print(pick_name()) # Sik | |
# now the developer pushes a new and improved version | |
pick_name <- function() { | |
names <- c("Dax", "Wug", "Lep", "Sik", "Bop") | |
sample(names, size = 1) | |
} | |
# my output is no longer reproducible... | |
set.seed(100) | |
print("--- Attempt 3 ---") | |
print(pick_name()) # Wug | |
print(pick_name()) # Lep | |
print(pick_name()) # Dax | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment