Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
    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]);
    }
Ejemplo n.º 4
0
 public static int RandomInt(int min, int max, IRandomProvider random)
 {
     return(random.RandomInt(min, max));
 }
Ejemplo n.º 5
0
 // returns an int in [min, max[
 //
 public static int RandomInt(int min, int max)
 {
     return(rng_.RandomInt(min, max));
 }
Ejemplo n.º 6
0
 public static Direction[] GetRandomDirections(IRandomProvider random)
 {
     return(directions.OrderBy(x => random.RandomInt(0, int.MaxValue)).ToArray());
 }