I'm writing an alphabet cipher that ciphers at random. It looks like it should work when I'm debugging it but when I look at the cipher key it comes out with duplicate letters like some of them weren't switched during the for loop. Any help is much appreciated. WasSwapped is used to keep track of whether the letters been used in the cipher already and alphabet is just a list of the alphabet in order. All arrays and lists are size 26.

List<String^>^ encryptAlphabet = gcnew List<String^>();
array<bool>^ wasSwapped = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
Random^ rand = gcnew Random();
int temp;
encryptAlphabet = alphabet;
for(int i =0; i < 26; i++)
{
    temp = rand->Next(26);
    if(wasSwapped[temp] ==false)
    {
	encryptAlphabet[i] = alphabet[temp];
	wasSwapped[temp] = true;
    }
    else
    {
	i -= 1;
    }
}

Hey guys. I'm back. It ended up being a problem with the lists. It works fine when I change them to arrays which is acceptable in this situation. Thanks everyone who took a look.

This question has already been answered. Start a new discussion instead.