Exemplo n.º 1
0
        public TValue GetNextValue()
        {
            TValue random = default(TValue);

            if (typeof(TValue) == typeof(int))
            {
                int    a    = (int)Convert.ChangeType(UpperBound, typeof(int));
                int    b    = (int)Convert.ChangeType(LowerBound, typeof(int));
                double rand = _Randomizer.NextDouble();

                int val = OrionMath.LinearInterpolate(a, b, rand);
                random = (TValue)Convert.ChangeType(val, typeof(TValue));
            }
            else if (typeof(TValue) == typeof(float))
            {
                float  a    = (float)Convert.ChangeType(UpperBound, typeof(float));
                float  b    = (float)Convert.ChangeType(LowerBound, typeof(float));
                double rand = _Randomizer.NextDouble();

                float val = OrionMath.LinearInterpolate(a, b, rand);
                random = (TValue)Convert.ChangeType(val, typeof(TValue));
            }
            else if (typeof(TValue) == typeof(double))
            {
                double a    = (double)Convert.ChangeType(UpperBound, typeof(double));
                double b    = (double)Convert.ChangeType(LowerBound, typeof(double));
                double rand = _Randomizer.NextDouble();

                double val = OrionMath.LinearInterpolate(a, b, rand);
                random = (TValue)Convert.ChangeType(val, typeof(TValue));
            }
            else if (typeof(TValue) == typeof(Vector2))
            {
                Vector2 a    = (Vector2)Convert.ChangeType(UpperBound, typeof(Vector2));
                Vector2 b    = (Vector2)Convert.ChangeType(LowerBound, typeof(Vector2));
                double  rand = _Randomizer.NextDouble();

                Vector2 val = OrionMath.LinearInterpolate(a, b, rand);
                random = (TValue)Convert.ChangeType(val, typeof(TValue));
            }
            else if (typeof(TValue) == typeof(Color))
            {
                Color  a    = (Color)Convert.ChangeType(UpperBound, typeof(Color));
                Color  b    = (Color)Convert.ChangeType(LowerBound, typeof(Color));
                double rand = _Randomizer.NextDouble();

                Color val = OrionMath.LinearInterpolate(a, b, rand);
                random = (TValue)Convert.ChangeType(val, typeof(TValue));
            }

            return(random);
        }