Skip to content

Instantly share code, notes, and snippets.

@JosmanPS
Last active March 16, 2016 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosmanPS/5b5a2bab7b9bd322ec36 to your computer and use it in GitHub Desktop.
Save JosmanPS/5b5a2bab7b9bd322ec36 to your computer and use it in GitHub Desktop.
Función para crear un ID aleatorio con las especificaciones de Carito
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