public static Gene Generate(GeneConfiguration config, bool isActual) { if (config.Fibonacci && RandomizationProvider.Current.GetType() != typeof(FibonacciRandomization)) { RandomizationProvider.Current = _fibonacci; } else if (_basic != null) { RandomizationProvider.Current = _basic; } if (isActual && config.Actual.HasValue) { return(new Gene(new KeyValuePair <string, object>(config.Key, config.Actual))); } return(new Gene(new KeyValuePair <string, object>(config.Key, GeneFactory.RandomBetween(config.Min.Value, config.Max.Value, config.Precision)))); }
/// <summary> /// Generate gene randomly withing acceptable boundaries set by GeneConfiguration. /// </summary> /// <param name="config">Gene configuration.</param> public static Gene GenerateRandom(GeneConfiguration config) { // generate random decimal within an interval if (config.MinDecimal.HasValue && config.MaxDecimal.HasValue) { var randomDecimal = RandomBetween(config.MinDecimal.Value, config.MaxDecimal.Value); return(new Gene(randomDecimal)); } // if no decimal nor int values specified - there is a mistake. if (!config.MinInt.HasValue || !config.MaxInt.HasValue) { throw new Exception("GeneFactory ~ GenerateRandom => Gene configuration is invalid"); } // if has int values interval - generate random int in between. var randomInteger = RandomBetween(config.MinInt.Value, config.MaxInt.Value); return(new Gene(randomInteger)); }