void GenerateCountries() { if (settings.RandomCountriesCount == 0) { return; } IList <string> validCityIds = entityManager .GetCities() .Where(city => city.IsHabitable && entityManager.GetCountries().All(country => country.CapitalId != city.Id && country.Name != city.NameId)) .GroupBy(x => x.NameId) .Select(g => g.GetRandomElement(rng.Randomiser)) .Select(x => x.Id) .ToList(); for (int i = 0; i < settings.RandomCountriesCount; i++) { string cityId = validCityIds.GetRandomElement(rng.Randomiser); Country country = countryGenerator.GenerateCountry(cityId); entityManager.AddCountry(country); validCityIds.Remove(cityId); } }