/// <summary> /// Products destroyed by decay. /// </summary> /// <param name="amount">The amount being checked against.</param> /// <param name="MaintenanceMet">The percent of maintenance met.</param> /// <returns>The number of failed products.</returns> public double FailedProducts(double amount, double MaintenanceMet) { if (amount <= 0) { throw new ArgumentOutOfRangeException("Amount bust be greater than 0."); } if (MaintenanceMet < 0 || MaintenanceMet > 1) { throw new ArgumentOutOfRangeException("Maintenance Met must be between 0 and 1."); } // get the current failure chance, modified by maintenance met. var currentFailChance = DailyFailureChance * (2 - MaintenanceMet); // Get the percent of failure today, // stopping at zero so new items don't magically come into existance. var normalizedFailure = Math.Max(randomizer.Normal(1, 1) * currentFailChance, 0); // How many failed today. var randFailures = Math.Floor(normalizedFailure * amount); // Get an additional base chance that something break to push towards failure. var baseResult = randomizer.NextDouble() >= currentFailChance ? 0 : 1; // Return the sum of our random Failures and our base, capping at the total amount for safety. return(Math.Min(amount, randFailures + baseResult)); }