Randomly choose children gameobjects in a for loop

I’m working on a simple village building game in Unity3D, C#. I made it so the game would generate a 50x50 block of ground that is made up of clones of a prefab. These clones are children of a gameobject called Ground. They are called groundChild in the script, and the parent of those children is called groundParent in the script. My script currently:

//GameObjects
public GameObject cube;
public GameObject groundParent;
private GameObject forestObject;

//Integers
public int worldWidthX;
public int worldWidthZ;
public int mapHeight;

//Floats
private float mapSizeX;
private float mapSizeZ;

private float forestMaxAmount;
private float forestMinAmount;
private float forestAmount;
private float forestObjectNumber;

public List<Transform> forestObjects = new List<Transform> ();

public void GenerateTerrain()
{
	for(int x = 0; x <= this.worldWidthX; x++, x++)
	{
		for(int z = 0; z <= this.worldWidthZ; z++, z++)
		{
			float y = /*Mathf.PerlinNoise(x / 30, 76) * Mathf.PerlinNoise(z / 30, 22) * 40;*/ mapHeight;
			GameObject groundChild = Instantiate(this.cube, new Vector3(x, y, z), this.cube.transform.rotation);
			groundChild.transform.parent = groundParent.transform;
		}
	}

	forestMaxAmount = (worldWidthX * worldWidthZ) / 8;
	forestMinAmount = (worldWidthX * worldWidthZ) / 25;

	forestAmount = Mathf.RoundToInt(Random.Range (forestMinAmount, forestMaxAmount));
	Debug.Log (forestAmount);

	for (var i = 0; i <= forestAmount; i++) 
	{
		forestObjectNumber = Mathf.RoundToInt(Random.Range (forestMinAmount, forestMaxAmount));
	}

	/*foreach (GameObject child in groundParent.transform)
	{
		if (child.tag == "Forest")
		{
			//Add Trees
		}
	}*/
}

What I’m having trouble figuring out is how to correctly and randomly choose out of these children gameobjects and then apply a tag change to them.

Heres the simplest code snippet I can think of for that:

// I'm assuming forestAmount is how many random children you are trying to find
for (int i = 0; i < forestAmount; i++)
{
    int randomChildIdx = Math.Random(0, groundParent.transform.childCount);
    Transform randomChild = groundParent.transform.GetChild(randomChildIdx);
    // randomChild is now a random child of groundParent. Do whatever you need to with it.
}

The problem here is that you can get repeat random selections. If this is a problem, you can put the already selected indices in a HashSet:

HashSet<int> alreadyChosen = new HashSet<int>();
// I'm assuming forestAmount is how many random children you are trying to find
for (int i = 0; i < forestAmount; i++)
{
    int randomChildIdx = Math.Random(0, groundParent.transform.childCount);
    while (alreadyChosen.Contains(randomChildIx))
        randomChildIdx = Math.Random(0, groundParent.transform.childCount);

    alreadyChosen.Add(randomChildIdx);
    Transform randomChild = groundParent.transform.GetChild(randomChildIdx);
    // randomChild is now a random child of groundParent. Do whatever you need to with it.
}

Note: this script is not safe if the number of children is less than forestAmount and will have worse performance as forestAmount gets closer to the number of children. These issues can be worked around, but the script gets more complicated then - stick with the simple solution if it works.