How can I limit the number of gems that spawn at the start of my match three game.

I am creating a match three style game. Currently, at the start of the game, all the tiles are filled with gems. I would like to limit the number of tiles that spawn at the start to a certain number. I have been trying for hours I can not figure a solution any help would be appreciated. Here is the code before trying to implement this limitation.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Board : MonoBehaviour
{
     public int width;
     public int height;
     public GameObject bgTilePrefab;
     public Gem[] gems;
     public Gem[,] allGems;
     // Start is called before the first frame update
     void Start()
     {
         allGems = new Gem[width, height];
         Setup();
     }
     private void Update()
     {
     }
     private void Setup()
     {
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 Vector2 pos = new Vector2(x, y);
                 GameObject bgTile = Instantiate(bgTilePrefab, pos, Quaternion.identity);
                 bgTile.transform.parent = transform; //is this necessary?
                 bgTile.name = "BG Tile - " + x + ", " + y;
                 int gemToUse = Random.Range(0, gems.Length);
                  SpawnGem(new Vector2Int(x, y), gems[gemToUse]);
             }
         }
     }
     private void SpawnGem(Vector2Int pos, Gem gemToSpawn)
     {
         {
            
             Gem gem = Instantiate(gemToSpawn, new Vector3(pos.x, pos.y, 0f), Quaternion.identity);
             gem.transform.parent = transform;
             gem.name = "Gem - " + pos.x + ", " + pos.y;
             allGems[pos.x, pos.y] = gem;
             gem.SetupGem(pos, this);
         }
     }
}

What’s wrong with your current code?

Generate a Vector2 List of all positions. In a method create a temp copy and a for loop limited by the number of gems you want to spawn. Randomly pick a value (int) between 0 and temp.Count-1. This Vector2 index is now where to Instantiate a gem. Remove that position from the temp list and loop again until you have placed the number of gems indicated in the for loop conditional.