// Noise selector is experimental feature to make spawn distribution always the same.
        // For example, if one area was cleaned of objects, the random selector will help us to ensure that objects
        // will be respawned in this area and not in other areas.
        private NoiseSelector CreateTileRandomSelector(double density, ObjectSpawnPreset preset, int desiredCount)
        {
            var seed = (this.Id.GetHashCode() * 397) ^ preset.GetHashCode();

            // we need to use a little bit higher density in our noise selector,
            // otherwise it will be always impossible to spawn the full amount of objects
            density *= 1.065;

            var minDensity = 0.0;

            if (desiredCount < 10)
            {
                // ensure that min density is high enough to allow spawning of these objects
                minDensity = 0.1;
            }

            // clamp density
            density = MathHelper.Clamp(density, minDensity, max: 1);

            return(new NoiseSelector(
                       from: 0,
                       to: density,
                       noise: new WhiteNoise(seed: seed)));
        }