I want to keep checking if a number is already used until it's not.

This is where my head is at and I could be totally wrong on my approch.

//List of all the used times for the day
List<int> usedTimes = new List<int>();
//Gets a random number between the players preferred start and end time
int randomTime = Random.Range(1, 4);

for (int i = 0; i <= usedTimes.Count; i++) {
    if(randomTime != usedTimes*) {*

//Adds the number to the already used times list
usedTimes.Add(randomTime);
} else {
randomTime = Random.Range(1, 4);
}
}
But I want to keep checking to see if randomTime is used in the usedTimes list until it’s not. If it is already used I want to get a new randomTime then check to see if that is used again. As of now it gets a random time then checks if it is used. If it is, it just gets a new random time that could possible get the same result or could possible get another number that is already added to the usedTimes list. I feel like I am going about this all wrong.

There are a couple of issues with this code. Firstly, the for loop should be a while loop because it needs to keep running until it finds a number that is not in the usedTimes list. Secondly, the usedTimes list should not be modified within the loop because this can cause an infinite loop if the usedTimes list is not updated. Here is an example of how the code could be rewritten:

//List of all the used times for the day
List<int> usedTimes = new List<int>();

int randomTime = Random.Range(1, 4);
while (usedTimes.Contains(randomTime))
{
    randomTime = Random.Range(1, 4);
}

usedTimes.Add(randomTime);

This code will keep generating a new random number and checking if it is in the usedTimes list until it finds a number that is not in the list. It will then add that number to the usedTimes list.
Accept it as ANSWER if it works or Let me know.