Last active
March 16, 2016 22:21
-
-
Save JosmanPS/5b5a2bab7b9bd322ec36 to your computer and use it in GitHub Desktop.
Función para crear un ID aleatorio con las especificaciones de Carito
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
random_id <- function() { | |
# Random string part | |
r_string <- rawToChar(as.raw(sample(65:90, 3, replace=T))) | |
# Random numeric part | |
r_num <- toString(sample(0:9, 4, replace=T)) | |
r_num <- gsub(", ", "", r_num) | |
return(paste0(r_string, r_num, sep="")) | |
} | |
seed_id <- function(seed) { | |
# Para evitar que salgan resultados repetidos por probabilidad | |
# Ej: | |
# seed_id(1), seed_id(2), ... | |
set.seed(seed) | |
# Random string part | |
r_string <- rawToChar(as.raw(sample(65:90, 3, replace=T))) | |
# Random numeric part | |
r_num <- toString(sample(0:9, 4, replace=T)) | |
r_num <- gsub(", ", "", r_num) | |
return(paste0(r_string, r_num, sep="")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment