public static KeyValuePair <int, T> GetRandomElementWithIndex <T>(this ICollection <T> collection) { var randomIndex = RandomFactory.GetInstance().Next(collection.Count); var randomElement = collection.ElementAtOrDefault(randomIndex); return(new KeyValuePair <int, T>(randomIndex, randomElement)); }
/// <summary> /// Creates a new instance of <see cref="DynamicParameterProvider"/> /// </summary> /// <param name="parameterSetListCapacity">Parameter set list capacity</param> public DynamicParameterProvider(int parameterSetListCapacity) { _random = RandomFactory.GetInstance(); _currentParameterSetIndex = 0; ParameterSets = GenerateRandomParameters(parameterSetListCapacity); WinningParameterSets = new List <Tuple <double, double> >(); }
/// <summary> /// Initializes a new instance of the <see cref="BaseHarmonyGenerator{T}"/> class. /// </summary> /// <param name="function">The function.</param> /// <exception cref="ArgumentNullException">function</exception> protected BaseHarmonyGenerator(IObjectiveFunction <T> function) { ObjectiveFunction = function ?? throw new ArgumentNullException(nameof(function)); Random = RandomFactory.GetInstance(); }
public static T GetRandomElement <T>(this ICollection <T> collection) { var randomIndex = RandomFactory.GetInstance().Next(collection.Count); return(collection.ElementAtOrDefault(randomIndex)); }
public static int GetRandomIndexMinimum <T>(this ICollection <T> collection, int startIndex) { return(RandomFactory.GetInstance().Next(startIndex, collection.Count)); }
public static int GetRandomIndex <T>(this ICollection <T> collection) { return(RandomFactory.GetInstance().Next(collection.Count)); }