I am attempting to generate a randomized key of letters which are only used once in the overall key. I currently have an array "regKey" which is storing the letters A-Z in its normal order. I would like to create a new array, "newKey" where the order of the letters are completely random but each and every letter is used when creating this new array. There should be no duplicates of any letter in the new array.
So far I've been able to generate a random key but often there are duplicates of certain letters. Here is my code below for reference.
public void keyGen() {
char [] regKey = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char [] newKey = new char [26];
int tempNum;
int totalChoice = 26;
Random rand = new Random();
for(int i = 0; i<26; i++) {
tempNum = rand.nextInt(totalChoice);
newKey[i] = regKey[tempNum];
System.out.print(newKey[i]);
}
String keyString = new String (newKey);
label_key.setText(keyString);
}