It is all in the title basically. It is simple, but I don't know why my While loop is failing sometimes. Every now and then I would get a list that is of length 2 instead of 3.
Here is my C# code:
public List<int> generateRequiredSecretCode()
{
List<int> placeHolder = new List<int>();
Random random = new Random();
int randomNo = random.Next(0, 10);
while (!placeHolder.Contains(randomNo) && placeHolder.Count != 3)
{
placeHolder.Add(randomNo);
randomNo = random.Next(0, 10);
}
return placeHolder;
}
Summary of my aim: I want a List of integers that is of length 3 and where each number in the list is between 0 and 9 and is unique