Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 25, 2020 18:49
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 parzibyte/8e3aba867690bfceacf7eb38539cca49 to your computer and use it in GitHub Desktop.
Save parzibyte/8e3aba867690bfceacf7eb38539cca49 to your computer and use it in GitHub Desktop.
public static String cadenaAleatoria(int longitud) {
// El banco de caracteres
String banco = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// La cadena en donde iremos agregando un carácter aleatorio
String cadena = "";
for (int x = 0; x < longitud; x++) {
int indiceAleatorio = numeroAleatorioEnRango(0, banco.length() - 1);
char caracterAleatorio = banco.charAt(indiceAleatorio);
cadena += caracterAleatorio;
}
return cadena;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment