public void ScaleValue_64_Test()
        {
            // This is a little overloaded- it covers all the cases within ScaleValue(this
            // Random, ulong)
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(ulong.MaxValue);   // cause a biased number if maxValue is even
            writer.Write(0x0000_0001_0000_0017);

            var buf    = mem.ToArray();
            var rng    = new NotRandomFromBytes(buf);
            var rnga   = rng.Aspect();
            var actual = rnga.NextLong(0x10);

            Assert.AreEqual(7, actual);

            rng    = new NotRandomFromBytes(buf); // start over
            actual = (long)rng.ScaleValue(0x10L);

            Assert.AreEqual(7, actual);

            var zero = 0ul;
            var z2   = zero.ScaleValue(1, ulong.MaxValue, out _);

            Assert.AreEqual(zero, z2);
        }
        public void Random_double_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(1L << 63);   // Exactly in the middle [0..uint.MaxValue+1]

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            var actual = rnga.NextDouble();

            Assert.AreEqual(0.5, actual);
        }
        public void Random_Next1a_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(uint.MaxValue);

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            // now we have an Aspect wrapping exactly 4 0xff bytes . The Aspect's Next operation
            // will request more bytes (as the first value will == int.MaxValue), and this time
            // the stream will not fail.
            var actual = rnga.Next(-1);
        }
        public void Random_Next0a_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(uint.MaxValue);

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            // now we have an Aspect wrapping exactly 4 0xff bytes. This will cause the Aspect's
            // Next operation to request more bytes (as the value will == int.MaxValue), and
            // cause the stream to fail.
            var actual = rnga.Next();
        }
        public void Random_Next2_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(uint.MaxValue);     // will cause bias
            writer.Write(uint.MaxValue - 1); // will be returned

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            var actual   = rnga.Next(int.MinValue, int.MaxValue);
            var expected = int.MaxValue - 1;

            Assert.AreEqual(expected, actual);
        }
        public void Random_Next1b_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(uint.MaxValue);
            writer.Write(42);

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            var actual   = rnga.Next(30);
            var expected = 42 % 30;

            Assert.AreEqual(expected, actual);
        }
        public void Random_Next0b_Test()
        {
            var mem    = new MemoryStream();
            var writer = new BinaryWriter(mem);

            writer.Write(uint.MaxValue);
            writer.Write(5);

            var rng  = new NotRandomFromBytes(mem.ToArray());
            var rnga = rng.Aspect();

            // now we have an Aspect wrapping exactly 4 0xff bytes followed by 4 bytes equalling
            // 5. The Aspect's Next operation will request more bytes (as the first value will
            // == int.MaxValue), and this time the stream will not fail.
            var actual = rnga.Next();

            Assert.AreEqual(5, actual);
        }