0
I need to generate a key that contains letters and numbers Ex: "AJ67G8". I am generating with Random from java.io.Serializable:
public static String nomeAleatorio(int nCaracteres) {
Random rand = new Random();
char[] letras = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i <= nCaracteres; i++) {
int ch = rand.nextInt(letras.length);
sb.append(letras[ch]);
}
return sb.toString();
}
This key has to be unique, the problem is that Ramdom doesn’t guarantee it and keep going to the bank every time to check if the key exists is too much work. What strategy to use to solve this problem?
https://answall.com/search?q=+fisher-yates
– Maniero