Tilemap Systetm

Im making a rogue like game and I made a tilemap system which works fine everything spawns as it shoulld all connected. Anyways my issue is that because I randomly generate the tiles I cant really find a way to make the same type of tiles x and x tille with the same sprite to not be next to each other does anyone have any idea on how I can fix this. Also is there a way I can limit the amount of the specific tile that can used for example a market tile can I limit it to saying there can be max 4 and min 1 thanks for your help.

(Example of the problem)

You could make a counter for each tile so that when you add one of that tile the counter goes up and when the number is over the limit, remove it from the array (if you are using one) so it can’t add that tile anymore. As for stopping the same tile from being placed next to each other, if you are using an array of tiles, once you add that, it could remove it from the array, wait for another one to be placed and then add it again. Although this would only work for specific scripts.