public static IEnumerable <T> TakeRandomFrom <T>(this IRandomizer randomizer, IEnumerable <T> source, int count) { var availableCount = source.Count(); if (availableCount == 0) { throw new Exception("Unable to pick random number from empty list"); } if (availableCount == count) { return(source); } var randomElements = new List <T>(); for (var i = 0; i < count; i++) { var random = randomizer.Random(0, availableCount - 1); var randomElement = source.Skip(random).First(); if (randomElements.Contains(randomElement)) { i--; continue; } randomElements.Add(randomElement); } return(randomElements); }
public static T TakeRandomFrom <T>(this IRandomizer randomizer, IEnumerable <T> source) { var availableCount = source.Count(); if (availableCount == 0) { throw new Exception("Unable to pick random number from empty list"); } var random = randomizer.Random(0, availableCount - 1); return(source.Skip(random).First()); }
public static float Random(this IRandomizer randomizer, ICurveFunction curve, float minValue, float maxValue) { var randomNumber = randomizer.Random(minValue, maxValue); var isNegative = minValue < 0; if (isNegative) { randomNumber = Math.Abs(randomNumber); maxValue = Math.Abs(minValue); } var result = curve.ScaledPlot(randomNumber, maxValue); return(isNegative ? -result : result); }
public double Random(double lower, double upper, bool floating) { var result = lower + _random.Random() * upper; return(floating ? result : (result < 0 ? _lodashMath.Ceil(result) : _lodashMath.Floor(result))); }
public static float Random(this IRandomizer randomizer, ICurveFunction curve) { var randomNumber = randomizer.Random(); return(curve.Plot(randomNumber)); }