Duplicate string characters

My code here isn’t functioning as I need.

What im trying to do is scan through my list of 10 letters. If any one letter exists in the list more than 2 times, I want to reset the list until all letters in list have 2 or less duplicates. Here is my wrong code:

int duplicates = 1;
			
		do
		{
		//Check for duplicate letters
		for (int x = 0; x < TotalPlayerLetters; x++)
		{
			for (int y = 1; y < TotalPlayerLetters; y++)
			{
				if (currentRack[x] == currentRack[y])
				{
					duplicates = 1;
					
					//Generate common letters
        			for (int q = 0; q < TotalPlayerLetters; q++)
        			{
						currentRack.Clear();
						
						Block temp = (Block)Blocks[q].GetComponent(typeof(Block));
						temp.transform.localScale = new Vector3(1.6f,1.6f,.15f);
			
            			int rand = Random.Range(0,COMMONLETTERS.Length);
            			currentRack.Insert(q,(COMMONLETTERS[rand]));
        			}
		
						//Place 2 random letters in the last two blocks
						int rand3 = Random.Range(0,FULLALPHABET.Length);
						int rand4 = Random.Range(0,FULLALPHABET.Length);
						currentRack[8] = FULLALPHABET[rand3];
						currentRack[9] = FULLALPHABET[rand4];
				}
				else duplicates = 0;
			}
		}
		} while (duplicates == 1);

I’d limit it at the time of list creation rather than use a while loop to check for duplicates. Something like this should work:

private var alphabet = Array("a","a","b","b","c","c","d","d","e","e","f","f","g","g","h","h","i","i","j","j","k","k","l","l","m","m","n","n","o","o","p","p","q","q","r","r","s","s","t","t","u","u","v","v","w","w","x","x","y","y","z","z");
private var letters = new String[10];

function Awake(){
	for (i=0; i<10; i++){
		var index = Random.Range(0, alphabet.length);
		letters[i] = alphabet[index] as String;
		alphabet.RemoveAt(index); //remove letter from alphabet
	}
	Debug.Log(Array(letters));
}

Thanks much! Never thought, even in the slightest to work it this way. Works great!