Esempio n. 1
0
File: Double.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random double array with option
 /// </summary>
 public static double[] NextDoubles(int length, double fromValue, double toValue, RandomNumberOption option)
 {
     var ret = new double[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 2
0
File: Float.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random float array with option
 /// </summary>
 public static float[] NextFloats(int length, float fromValue, float toValue, RandomNumberOption option)
 {
     var ret = new float[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 3
0
File: Double.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random double array with option
 /// </summary>
 public static double[] NextDoubles(int length, RandomNumberOption option)
 {
     var ret = new double[length];
     for (var i = 0; i < length; i++)
         ret[i] = RandomNumber.NextDouble(option);
     return ret;
 }
Esempio n. 4
0
 /// <summary>
 /// Returns a random decimal array with option
 /// </summary>
 public static decimal[] NextDecimals(int length, decimal fromValue, decimal toValue, RandomNumberOption option)
 {
     var ret = new decimal[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 5
0
 /// <summary>
 /// Returns a random decimal array with option
 /// </summary>
 public static decimal[] NextDecimals(int length, RandomNumberOption option)
 {
     var ret = new decimal[length];
     for (var i = 0; i < length; i++)
         ret[i] = RandomNumber.NextDecimal(option);
     return ret;
 }
Esempio n. 6
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint array with option
 /// </summary>
 public static uint[] NextUInts(int length, uint fromValue, uint toValue, RandomNumberOption option)
 {
     var ret = new uint[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 7
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint array with option
 /// </summary>
 public static uint[] NextUInts(int length, RandomNumberOption option)
 {
     var ret = new uint[length];
     for (var i = 0; i < length; i++)
         ret[i] = RandomNumber.NextUInt(option);
     return ret;
 }
Esempio n. 8
0
File: Short.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random short array with option
 /// </summary>
 public static short[] NextShorts(int length, short fromValue, short toValue, RandomNumberOption option)
 {
     var ret = new short[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 9
0
File: SByte.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random sbyte array with option
 /// </summary>
 public static sbyte[] NextSBytes(int length, sbyte fromValue, sbyte toValue, RandomNumberOption option)
 {
     var ret = new sbyte[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 10
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint with option
 /// </summary>
 public static uint NextUInt(RandomNumberOption option)
 {
     uint result;
     if (option.HasFlag(RandomNumberOption.CryptographySecure))
     {
         var buffer = new byte[SizeOfUInt]; // create new array to ensure thread safe
         do
         {
             CsPrng.Value.GetBytes(buffer);
             result = BitConverter.ToUInt32(buffer, 0);
         }
         while (
             (result == uint.MinValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
             || (result == uint.MaxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
         );
     }
     else
     {
         do
         {
             lock (_lock)
             {
                 result = Prng.Value.genrand_Int32();
             }
         }
         while (
             (result == uint.MinValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
             || (result == uint.MaxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
         );
     }
     return result;
 }
Esempio n. 11
0
File: Long.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random long array with option
 /// </summary>
 public static long[] NextLongs(int length, long fromValue, long toValue, RandomNumberOption option)
 {
     var ret = new long[length];
     for (var i = 0; i < length; i++)
         ret[i] = fromValue.RandomTo(toValue, option);
     return ret;
 }
Esempio n. 12
0
File: Long.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random long array with option
 /// </summary>
 public static long[] NextLongs(int length, RandomNumberOption option)
 {
     var ret = new long[length];
     for (var i = 0; i < length; i++)
         ret[i] = RandomNumber.NextLong(option);
     return ret;
 }
Esempio n. 13
0
File: Byte.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random byte array with option
 /// </summary>
 public static byte[] NextBytes(int length, RandomNumberOption option)
 {
     var ret = new byte[length];
     if (option.HasFlag(RandomNumberOption.CryptographySecure))
     {
         RandomNumber.CsPrng.Value.GetBytes(ret);
     }
     else
     {
         for (var i = 0; i < length; i++)
             ret[i] = RandomNumber.NextByte(option);
     }
     return ret;
 }
Esempio n. 14
0
File: Float.cs Progetto: leevox/sdk
        /// <summary>
        /// Returns a random float with option
        /// </summary>
        public static float NextFloat(RandomNumberOption option)
        {
            float result;

            if (option.HasFlag(RandomNumberOption.CryptographySecure))
                ReseedCsPrng();

            do {
                lock (_lock)
                {
                    result = Convert.ToSingle(Prng.Value.genrand_res53());
                }
            }
            while (
                (result < float.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMinValue))
                || (1 - result < float.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
            );
            return result;
        }
Esempio n. 15
0
        /// <summary>
        /// Returns a random decimal with option
        /// </summary>
        public static decimal NextDecimal(RandomNumberOption option)
        {
            decimal result;

            if (option.HasFlag(RandomNumberOption.CryptographySecure))
                ReseedCsPrng();

            do {
                lock (_lock)
                {
                    result = Convert.ToDecimal(Prng.Value.genrand_res53());
                }
            }
            while (
                (result == 0 && option.HasFlag(RandomNumberOption.ExcludedMinValue))
                || (result == 1 && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
            );
            return result;
        }
Esempio n. 16
0
File: Double.cs Progetto: leevox/sdk
        /// <summary>
        /// Returns a random double with option
        /// </summary>
        public static double NextDouble(RandomNumberOption option)
        {
            double result;

            if (option.HasFlag(RandomNumberOption.CryptographySecure))
                ReseedCsPrng();

            do {
                lock (_lock)
                {
                    result = Prng.Value.genrand_res53();
                }
            }
            while (
                (result < double.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMinValue))
                || (1 - result < double.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
            );
            return result;
        }
Esempio n. 17
0
 /// <summary>
 /// Returns a random decimal between a range with option
 /// </summary>
 public static decimal NextDecimal(decimal minValue, decimal maxValue, RandomNumberOption option)
 {
     decimal result;
     do
     {
         result = NextDecimal(option);
         result = minValue + maxValue*result - minValue*result;
     }
     while (
         (result == minValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
         || (result == maxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
     );
     return result;
 }
Esempio n. 18
0
File: Long.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random long from value to value with option
 /// </summary>
 public static long RandomTo(this long fromValue, long toValue, RandomNumberOption option)
 {
     return fromValue < toValue ?
         RandomNumber.NextLong(fromValue, toValue, option)
         : RandomNumber.NextLong(toValue, fromValue, option);
 }
Esempio n. 19
0
File: Long.cs Progetto: leevox/sdk
        /// <summary>
        /// Returns a random long between a range with option
        /// </summary>
        public static long NextLong(long minValue, long maxValue, RandomNumberOption option)
        {
            long result;

            if (option.HasFlag(RandomNumberOption.CryptographySecure))
            {
                var buffer = new byte[SizeOfLong]; // create new array to ensure thread safe
                do
                {
                    CsPrng.Value.GetBytes(buffer);
                    result = BitConverter.ToInt64(buffer, 0);
                }
                while (
                    (result == long.MinValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
                    || (result == long.MaxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
                );
            }
            else
            {
                do
                {
                    var d = NextDouble(option);
                    result = Convert.ToInt64(minValue + maxValue*d - minValue*d);
                }
                while (
                    (result == minValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
                    || (result == maxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
                );
            }
            return result;
        }
Esempio n. 20
0
File: Short.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random short that greater than or equal to minValue with option
 /// </summary>
 public static short NextShort(short minValue, RandomNumberOption option)
     => NextShort(minValue, short.MaxValue, option);
Esempio n. 21
0
File: ULong.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random ulong that greater than or equal to minValue with option
 /// </summary>
 public static ulong NextULong(ulong minValue, RandomNumberOption option)
     => NextULong(minValue, ulong.MaxValue, option);
Esempio n. 22
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint from value to value with option
 /// </summary>
 public static uint RandomTo(this uint fromValue, uint toValue, RandomNumberOption option)
 {
     return fromValue < toValue ?
         RandomNumber.NextUInt(fromValue, toValue, option)
         : RandomNumber.NextUInt(toValue, fromValue, option);
 }
Esempio n. 23
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint between a range with option
 /// </summary>
 public static uint NextUInt(uint minValue, uint maxValue, RandomNumberOption option)
 {
     uint result;
     do
     {
         var d = NextDouble(option);
         result = (uint)(minValue + maxValue*d - minValue*d);
     }
     while (
         (result == minValue && option.HasFlag(RandomNumberOption.ExcludedMinValue))
         || (result == maxValue && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
     );
     return result;
 }
Esempio n. 24
0
File: UInt.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random uint that greater than or equal to minValue with option
 /// </summary>
 public static uint NextUInt(uint minValue, RandomNumberOption option)
     => NextUInt(minValue, uint.MaxValue, option);
Esempio n. 25
0
File: Double.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random double that greater than or equal to minValue with option
 /// </summary>
 public static double NextDouble(double minValue, RandomNumberOption option)
     => NextDouble(minValue, double.MaxValue, option);
Esempio n. 26
0
File: Double.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random double between a range with option
 /// </summary>
 public static double NextDouble(double minValue, double maxValue, RandomNumberOption option)
 {
     double result;
     do
     {
         result = NextDouble(option);
         result = minValue + maxValue*result - minValue*result;
     }
     while (
         (result - minValue < double.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMinValue))
         || (maxValue - result < double.Epsilon && option.HasFlag(RandomNumberOption.ExcludedMaxValue))
     );
     return result;
 }
Esempio n. 27
0
File: Double.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random double from value to value with option
 /// </summary>
 public static double RandomTo(this double fromValue, double toValue, RandomNumberOption option)
 {
     return fromValue < toValue ?
         RandomNumber.NextDouble(fromValue, toValue, option)
         : RandomNumber.NextDouble(toValue, fromValue, option);
 }
Esempio n. 28
0
 /// <summary>
 /// Returns a random decimal that greater than or equal to minValue with option
 /// </summary>
 public static decimal NextDecimal(decimal minValue, RandomNumberOption option)
     => NextDecimal(minValue, decimal.MaxValue, option);
Esempio n. 29
0
File: Long.cs Progetto: leevox/sdk
 /// <summary>
 /// Returns a random long that greater than or equal to minValue with option
 /// </summary>
 public static long NextLong(long minValue, RandomNumberOption option)
     => NextLong(minValue, long.MaxValue, option);
Esempio n. 30
0
 /// <summary>
 /// Returns a random decimal from value to value with option
 /// </summary>
 public static decimal RandomTo(this decimal fromValue, decimal toValue, RandomNumberOption option)
 {
     return fromValue < toValue ?
         RandomNumber.NextDecimal(fromValue, toValue, option)
         : RandomNumber.NextDecimal(toValue, fromValue, option);
 }