Ejemplo n.º 1
0
        //4d6+8 would be: Utility.Dice( 4, 6, 8 )
        public static int Dice(uint numDice, uint numSides, int bonus)
        {
            int  total = 0;
            uint sides = numSides;

            for (int i = 0; i < numDice; ++i)
            {
                total += (int)RandomImpl.Next(sides) + 1;
            }

            return(total + bonus);
        }
Ejemplo n.º 2
0
        public static void Shuffle <T>(IList <T> list)
        {
            int count = list.Count;

            for (int i = count - 1; i > 0; i--)
            {
                int r    = (int)RandomImpl.Next((uint)count);
                T   swap = list[r];
                list[r] = list[i];
                list[i] = swap;
            }
        }
Ejemplo n.º 3
0
        public static T[] Shuffle <T>(this T[] source, int index, int length)
        {
            T[]    sorted  = new T[source.Length];
            byte[] randoms = new byte[sorted.Length];

            source.CopyTo(sorted, 0);

            RandomImpl.NextBytes(randoms);
            Array.Sort(randoms, sorted, index, length);

            return(sorted);
        }
Ejemplo n.º 4
0
        //4d6+8 would be: Utility.Dice( 4, 6, 8 )
        public static int Dice(int numDice, int numSides, int bonus)
        {
            int total = 0;

            for (int i = 0; i < numDice; ++i)
            {
                total += RandomImpl.Next(numSides) + 1;
            }

            total += bonus;
            return(total);
        }
Ejemplo n.º 5
0
        public static bool PercentageBooleanGenerator(int chance)
        {
            int randomNo = RandomImpl.Next(101);

            if (randomNo <= chance)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static int Random(int from, int count)
        {
            if (count == 0)
            {
                return(from);
            }

            if (count > 0)
            {
                return((int)(from + RandomImpl.Next((uint)count)));
            }

            return((int)(from - RandomImpl.Next((uint)-count)));
        }
Ejemplo n.º 7
0
		public static int Random(int from, int count)
        {
            if (count == 0)
			{
				return from;
			}

            if (count > 0)
            {
                return from + RandomImpl.Next(count);
            }

            return from - RandomImpl.Next(-count);
        }
Ejemplo n.º 8
0
        public static int RandomMinMax(int min, int max)
        {
            if (min > max)
            {
                int copy = min;
                min = max;
                max = copy;
            }
            else if (min == max)
            {
                return(min);
            }

            return(min + RandomImpl.Next((max - min) + 1));
        }
Ejemplo n.º 9
0
        public static double RandomMinMax(double min, double max)
        {
            if (min > max)
            {
                double copy = min;
                min = max;
                max = copy;
            }
            else if (min == max)
            {
                return(min);
            }

            return(min + (RandomImpl.NextDouble() * (max - min)));
        }
Ejemplo n.º 10
0
 public static int Random(int from, int count)
 {
     if (count == 0)
     {
         return(from);
     }
     else if (count > 0)
     {
         return(from + RandomImpl.Next(count));
     }
     else
     {
         return(from - RandomImpl.Next(-count));
     }
 }
Ejemplo n.º 11
0
 public static int Random(uint count) => (int)RandomImpl.Next(count);
Ejemplo n.º 12
0
 public static bool RandomBool()
 {
     return(RandomImpl.NextBool());
 }
Ejemplo n.º 13
0
 public static int RandomList(params int[] list)
 {
     return(list[RandomImpl.Next(list.Length)]);
 }
Ejemplo n.º 14
0
 public static object RandomList(ArrayList list)
 {
     return(list[RandomImpl.Next(list.Count)]);
 }
Ejemplo n.º 15
0
 public static T RandomList <T>(params T[] list)
 {
     return(list[RandomImpl.Next(list.Length)]);
 }
Ejemplo n.º 16
0
 public static double RandomDouble() => RandomImpl.NextDouble();
Ejemplo n.º 17
0
 public static T RandomList <T>(List <T> list)
 {
     return(list[RandomImpl.Next(list.Count)]);
 }
Ejemplo n.º 18
0
 public static void RandomBytes(byte[] buffer)
 {
     RandomImpl.NextBytes(buffer);
 }
Ejemplo n.º 19
0
 public static bool RandomBool() => RandomImpl.NextBool();
Ejemplo n.º 20
0
 public static int Random(int count)
 {
     return(RandomImpl.Next(count));
 }
Ejemplo n.º 21
0
 public static void RandomBytes(byte[] buffer) => RandomImpl.GetBytes(buffer);
Ejemplo n.º 22
0
 public static double RandomDouble()
 {
     return(RandomImpl.NextDouble());
 }
Ejemplo n.º 23
0
 public static void RandomBytes(Span <byte> buffer) => RandomImpl.GetBytes(buffer);