Good afternoon, well, I am generating a random hexadecimal string in this pattern: 81c1328d-4dae-4af7-9974-893bb8ec90d4
But I would like to optimize this code here:
public String geraKee(){
String letras = "abcdef0123456789";
Random random = new Random();
String armazenaChaves = "";
int index = -1;
for( int i = 0; i < 8; i++ ) {
index = random.nextInt( letras.length() );
armazenaChaves += letras.substring( index, index + 1 );
}
armazenaChaves += "-";
for( int i = 0; i < 4; i++ ) {
index = random.nextInt( letras.length() );
armazenaChaves += letras.substring( index, index + 1 );
}
armazenaChaves += "-4";
for( int i = 0; i < 3; i++ ) {
index = random.nextInt( letras.length() );
armazenaChaves += letras.substring( index, index + 1 );
}
armazenaChaves += "-";
for( int i = 0; i < 4; i++ ) {
index = random.nextInt( letras.length() );
armazenaChaves += letras.substring( index, index + 1 );
}
armazenaChaves += "-";
for( int i = 0; i < 12; i++ ) {
index = random.nextInt( letras.length() );
armazenaChaves += letras.substring( index, index + 1 );
}
return armazenaChaves;
}