NextBytes() public method

Fills the provided byte array with random bytes. This method is functionally equivalent to System.Random.NextBytes().
public NextBytes ( byte buffer ) : void
buffer byte
return void
示例#1
0
 public void NextBytes()
 {
     int sampleCount = 10000000;
     XorShiftRandom rng = new XorShiftRandom();
     byte[] sampleArr = new byte[sampleCount];
     rng.NextBytes(sampleArr);
     NextByteInner(sampleArr);
 }
示例#2
0
        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);
        }