Example #1
0
        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);
        }
Example #2
0
        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());
        }
Example #3
0
        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);
        }
Example #4
0
        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)));
        }
Example #5
0
        public static float Random(this IRandomizer randomizer, ICurveFunction curve)
        {
            var randomNumber = randomizer.Random();

            return(curve.Plot(randomNumber));
        }