//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); }
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; } }
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); }
//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); }
public static bool PercentageBooleanGenerator(int chance) { int randomNo = RandomImpl.Next(101); if (randomNo <= chance) { return(true); } else { return(false); } }
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))); }
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); }
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)); }
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))); }
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)); } }
public static int Random(uint count) => (int)RandomImpl.Next(count);
public static bool RandomBool() { return(RandomImpl.NextBool()); }
public static int RandomList(params int[] list) { return(list[RandomImpl.Next(list.Length)]); }
public static object RandomList(ArrayList list) { return(list[RandomImpl.Next(list.Count)]); }
public static T RandomList <T>(params T[] list) { return(list[RandomImpl.Next(list.Length)]); }
public static double RandomDouble() => RandomImpl.NextDouble();
public static T RandomList <T>(List <T> list) { return(list[RandomImpl.Next(list.Count)]); }
public static void RandomBytes(byte[] buffer) { RandomImpl.NextBytes(buffer); }
public static bool RandomBool() => RandomImpl.NextBool();
public static int Random(int count) { return(RandomImpl.Next(count)); }
public static void RandomBytes(byte[] buffer) => RandomImpl.GetBytes(buffer);
public static double RandomDouble() { return(RandomImpl.NextDouble()); }
public static void RandomBytes(Span <byte> buffer) => RandomImpl.GetBytes(buffer);