예제 #1
0
 public void NextBool()
 {
     for (int i = 0; i < __loops; i++)
     {
         _rng.NextBool();
     }
 }
예제 #2
0
        public void NextBool()
        {
            int            sampleCount = 10000000;
            XorShiftRandom rng         = new XorShiftRandom();

            int    trueCount = 0, falseCount = 0;
            double maxExpectedCountErr = sampleCount / 25.0;

            for (int i = 0; i < sampleCount; i++)
            {
                if (rng.NextBool())
                {
                    trueCount++;
                }
                else
                {
                    falseCount++;
                }
            }

            double countErr = Math.Abs(trueCount - falseCount);

            if (countErr > maxExpectedCountErr)
            {
                Assert.Fail();
            }
        }
예제 #3
0
        private IntPoint[] GenerateRandomTestCase(int largeBoxRelativePos)
        {
            // Randomly select a position for the small box (the box is a single pixel in size).
            IntPoint smallBoxPos = new IntPoint(_rng.Next(TestFieldResolution), _rng.Next(TestFieldResolution));

            // Large box center is 5 pixels to the right, down or diagonally from the small box.
            IntPoint largeBoxPos = smallBoxPos;

            switch (largeBoxRelativePos)
            {
            case 0:     // Right
                largeBoxPos._x += 5;
                break;

            case 1:     // Down
                largeBoxPos._y += 5;
                break;

            case 2:     // Diagonal
                // Two alternate position get us to exactly 5 pixels distant from the small box.
                if (_rng.NextBool())
                {
                    largeBoxPos._x += 3;
                    largeBoxPos._y += 4;
                }
                else
                {
                    largeBoxPos._x += 4;
                    largeBoxPos._y += 3;
                }
                break;
            }

            // Handle cases where the large box is outside the visual field or overlapping the edge.
            if (largeBoxPos._x > CoordBoundIdx)
            {   // Wrap around.
                largeBoxPos._x -= TestFieldResolution;

                if (0 == largeBoxPos._x)
                {   // Move box fully into the visual field.
                    largeBoxPos._x++;
                }
            }
            else if (CoordBoundIdx == largeBoxPos._x)
            {   // Move box fully into the visual field.
                largeBoxPos._x--;
            }
            else if (0 == largeBoxPos._x)
            {   // Move box fully into the visual field.
                largeBoxPos._x++;
            }


            if (largeBoxPos._y > CoordBoundIdx)
            {   // Wrap around.
                largeBoxPos._y -= TestFieldResolution;

                if (0 == largeBoxPos._y)
                {   // Move box fully into the visual field.
                    largeBoxPos._y++;
                }
            }
            else if (CoordBoundIdx == largeBoxPos._y)
            {   // Move box fully into the visual field.
                largeBoxPos._y--;
            }
            else if (0 == largeBoxPos._y)
            {   // Move box fully into the visual field.
                largeBoxPos._y++;
            }
            return(new IntPoint[] { smallBoxPos, largeBoxPos });
        }