Just loop over the creation until your condition is satisfied:
var forbidden = new List<Tuple<int, int>>();
forbidden.Add(new Tuple<int, int>(5, 5));
forbidden.Add(new Tuple<int, int>(7, 9));
while(true)
{
x = random.Next(0, 20);
y = random.Next(0, 20);
if(forbidden.All(t => x != t.Item1 || y != t.Item2)) break;
}
This way, the loop will only terminate if you have coordinates that are “allowed”, i.e. reach the break
statement.
3
solved How can I have xy coordinates in a grid that can’t be used? [closed]