private void RandomlyRemoveRooms( Random rng) { int originalRoomCount = m_roomGrid.GetLength(0) * m_roomGrid.GetLength(1) * m_roomGrid.GetLength(2); int roomCount = originalRoomCount; // Determine the minimum number of rooms we allow for this level Range <float> roomDensityRange = m_worldTemplate.DungeonRoomDensity; float roomDensity = RNGUtilities.RandomFloat(rng, roomDensityRange.Min, roomDensityRange.Max); int minRoomCount = (int)(Math.Ceiling((float)originalRoomCount * roomDensity)); // Generate a randomized list of rooms IList <RoomIndex> randomRoomIndices = GetRoomIndexList(); RNGUtilities.DeterministicKnuthShuffle(rng, randomRoomIndices); // Randomly remove rooms one at time until we can't remove any more foreach (RoomIndex roomIndex in randomRoomIndices) { if (CanRemoveRoomFromGrid(roomIndex)) { RemoveRoomFromGrid(roomIndex); roomCount--; if (roomCount <= minRoomCount) { break; } } } }