I want to genrate 5 digit extremly secure random numbers for some products verifications which should be always unique, their no limits how many times in day or how many times in a week i've to put this request for new generation of manual codes, and it can be in range of 1k - 20k, The main requirement is about to manual codes should have to be always UNIQUE(NON REPEATED) otherwise their would be a big clash.
so please assit me a better and secured way to genrated 5 digit unique codes, Any recommendations would be very helpful.
for now i am using this reffrence :
private static final Random random = new Random();
private static final String CHARS = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ234567890!@#$";
public static String getToken(int length) {
StringBuilder token = new StringBuilder(length);
for (int i = 0; i < length; i++) {
token.append(CHARS.charAt(random.nextInt(CHARS.length())));
}
return token.toString();
}
Aucun commentaire:
Enregistrer un commentaire