Question: ```
            List<int> boardmove = new List<int>();
            boardmove.Add(0);
            boardmove.Add(1);
            boardmove.Add(2);
            boardmove.Add(3);
            boardmove.Add(4);
            boardmove.Add(5);
            boardmove.Add(6);
            boardmove.Add(7);
            boardmove.Add(8);

            int rand = rnd.Next(1, count);

            int num_one = boardmove[rand];

            boardmove.RemoveAt(num_one);

            count--;

```

I am trying to implement a computer player for my tic tac toe game. I am using a list to move the computer player, I want to index in the list and then remove the value I have selected. I want to select a unique value from the list each time.

```
            List<int> boardmove = new List<int>();
            boardmove.Add(0);
            boardmove.Add(1);
            boardmove.Add(2);
            boardmove.Add(3);
            boardmove.Add(4);
            boardmove.Add(5);
            boardmove.Add(6);
            boardmove.Add(7);
            boardmove.Add(8);

            int selectedIndex = rnd.Next(0, boardmove.Count);

            int selectedMove= boardmove[selectedIndex];
            Console.WriteLine(selectedMove);

            boardmove.RemoveAt(selectedIndex);
            Console.WriteLine(selectedIndex);

```

[![enter image description here](https://i.stack.imgur.com/s0iGW.png)](https://i.stack.imgur.com/s0iGW.png)

Answer: 
```
            Random rnd = new Random();

        List<int> boardmove = new List<int>(9);
        for (int i = 1; i < 10; i++)
            boardmove.Add(i);

        while (gameOver==false)
        {
            Console.Write("Enter X spot (1-9): ");
            int num = Convert.ToInt32(Console.ReadLine());

            int selectedIndex = rnd.Next(1, boardmove.Count);

            int selectedMove= boardmove[selectedIndex];
            Console.WriteLine(selectedMove);

            boardmove.RemoveAt(selectedIndex);

```

I have figured out my problem by moving my list initialization before my while loop
```
        Random rnd = new Random();

        List<int> boardmove = new List<int>(9);
        for (int i = 1; i < 10; i++)
            boardmove.Add(i);

        while (gameOver==false)
        {
            Console.Write("Enter X spot (1-9): ");
            int selectedMoveX= Convert.ToInt32(Console.ReadLine());

            int selectedIndex = rnd.Next(1, boardmove.Count);

            int selectedMoveO= boardmove[selectedIndex];

            boardmove.RemoveAt(selectedMoveX);
            boardmove.RemoveAt(selectedIndex);

            switch (selectedMoveX)

```

this code works correctly I am posting so that I can help others. is there anyway I can make the X input more bulletproof.