private void RandomIntConsistencyTest(IRandomProvider r) { int mintries = 1000; int maxtries = 10000; int min = 1; int max = 6; bool foundmin = false; bool foundmax = false; for (int i = 0; i < maxtries; i++) { int next = r.RandomInt(min, max); Assert.IsTrue(next >= min && next <= max); if (next == max) { foundmax = true; } if (next == min) { foundmin = true; } if (foundmax && foundmin && i > mintries) { break; } } Assert.IsTrue(foundmin); Assert.IsTrue(foundmax); }
public static int Roll(int dice, int sides, IRandomProvider random) { int sum = 0; for (int i = 0; i < dice; i++) { sum += random.RandomInt(1, sides); } return(sum); }
public static T GetRandom <T>(IList <T> items, IRandomProvider random) { if (items.Count == 0) { throw new Exception("Can't get a random item from an empty list"); } var index = random.RandomInt(0, items.Count); return(items[index]); }
public static int RandomInt(int min, int max, IRandomProvider random) { return(random.RandomInt(min, max)); }
// returns an int in [min, max[ // public static int RandomInt(int min, int max) { return(rng_.RandomInt(min, max)); }
public static Direction[] GetRandomDirections(IRandomProvider random) { return(directions.OrderBy(x => random.RandomInt(0, int.MaxValue)).ToArray()); }