Beispiel #1
0
 public void NextBytes100M()
 {
     for (int i = 0; i < 100; i++)
     {
         _rng.NextBytes(_buff);
     }
 }
Beispiel #2
0
        public void NextBytes()
        {
            int            sampleCount = 10000000;
            XorShiftRandom rng         = new XorShiftRandom();

            byte[] sampleArr = new byte[sampleCount];
            rng.NextBytes(sampleArr);
            NextByteInner(sampleArr);
        }
Beispiel #3
0
        public void NextBytes_LengthNotMultipleOfFour()
        {
            int            sampleCount = 10000003;
            XorShiftRandom rng         = new XorShiftRandom(0);

            byte[] sampleArr = new byte[sampleCount];
            rng.NextBytes(sampleArr);
            NextByteInner(sampleArr);

            // Note. We want to check that the last three bytes are being assigned random bytes, but the RNG
            // can generate zeroes, so this test is reliant on the RNG seed being fixed to ensure we have non-zero
            // values in those elements each time the test is run.
            Assert.IsTrue(sampleArr[sampleCount - 1] != 0);
            Assert.IsTrue(sampleArr[sampleCount - 2] != 0);
            Assert.IsTrue(sampleArr[sampleCount - 3] != 0);
        }
Beispiel #4
0
        private void PerformMutationOp_Write()
        {
            int buffLen = _rng.Next(1000);
            int offset  = _rng.Next(buffLen);
            int count   = _rng.Next(buffLen - offset);

            byte[] tmp = new byte[count];
            _rng.NextBytes(tmp);

            byte[] buff = new byte[buffLen];
            Array.Copy(tmp, 0, buff, offset, count);

            _strmA.Write(buff, offset, count);
            _strmB.Write(buff, offset, count);

            Debug.WriteLine(string.Format("Write offset={0}, count={1}", offset, count));
        }
        public void TestWriteZeroBytes()
        {
            byte[]            buf = new byte[0];
            MemoryBlockStream ms  = new MemoryBlockStream();

            ms.Write(buf, 0, 0);
            Assert.AreEqual(ms.Length, 0);

            XorShiftRandom rng = new XorShiftRandom(1234567);

            byte[] buf2 = new byte[100];
            rng.NextBytes(buf2);
            ms.Write(buf2, 0, buf2.Length);

            if (!Utils.AreEqual(ms.ToArray(), buf2))
            {
                Assert.Fail();
            }

            ms.Write(buf, 0, 0);
            Assert.AreEqual(ms.Length, buf2.Length);
        }