Instantiating GameObjects

I have been using the following code to instantiate 9 gameObjects. It works beautifully, but I want to be able to ensure that each object is instantiated an even number of times. Does anyone know how to do this? Thanks in advance for any help you can give.

void GenerateLevel()
{
    for (int x = -10; x < width; x++)
    {
        for (int y = -4; y < height; y++)
        {
            for (int i = 0; i < tilePrefabs.Length; i++)
            {
                if (Random.value > 0.5f) // 50% chance to place a tile
                {
                    int randomIndex = Random.Range(0, tilePrefabs.Length);
                    Vector2 position = new Vector2(x, y);
                    Instantiate(tilePrefabs[randomIndex], position, Quaternion.identity);
                }
            }
        }
    }
}

void FixedUpdate()
{
    if ((GameControl.control.matches >= 69) && (GameControl.control.matches < 207))
    {
        SceneManager.LoadScene("Level2");
    }
}

I could not find a way to ensure each GameObject appears an even number of times, which means that unused objects remain after any operation that is implemented.

Well, I can’t check the code because I don’t know the values of those width,height and tilePrefabs.Length, but if as you say the code works fine up to that point, won’t having two Instantiate one after the other with the same prefab fix the problem?

EDIT: sorry I just realized what you mean. I thought you meant each object to exist two times, let me think about it.

Actually, it instantiates a random number for each tilePrefab, so what I want is for it to instantiate an even number. So instead of instantiating 5, it should instantiate 4 or 6. Do you see what I mean?

I don’t understand as I look your code, what is the purpose of that last for loop. With this for there’s a big chance that you instantiate more than one GameObject in the same (x,y) coordinates, you can instantiate from zero to tilePrefabs.Length-1 Gameobjects in the same coordinates, is this desirable?

Anyway, one way I can think of, is to instantiate half your GameObjects randomly, while you keep the indexes in a collection. Then for the other half, you pick a random index number from that collection, you remove it from the collection and you instantiate the appropriate GameObject that has this index and keep doing that until your collection is empty. This will ensure an even number of each GameObject.