/// <inheritdoc/> public byte[] NextBytes(int length) { var result = new byte[length]; _random.FillBytes(result, 0, length); return(result); }
public void Test() { XoShiRo256StarStar random = null; var seed = new List <ulong>(); uint?uintValue; ulong?ulongValue; float?floatValue; double?doubleValue; byte?byteValue; var lines = File.ReadAllLines("Fixtures/xoshiro256starstar.out") .Select(line => line.Trim()) .ToArray(); for (var i = 0; i < lines.Length; i++) { if (string.IsNullOrWhiteSpace(lines[i]) || lines[i].StartsWith("#") || lines[i].StartsWith("//")) { continue; } else if (lines[i].StartsWith("Seed")) { seed = new List <ulong>(); while ((ulongValue = lines[++i].Replace("0x", "").ParseToULong(NumberStyles.HexNumber, CultureInfo.CurrentCulture)) != null) { seed.Add(ulongValue.Value); } } else if (lines[i].StartsWith("Integers")) { random = new XoShiRo256StarStar(seed.ToArray()); while ((uintValue = lines[++i].Replace("0x", "").ParseToUInt(NumberStyles.HexNumber, CultureInfo.CurrentCulture)) != null) { random.NextUInt().Should().Be(uintValue.Value, $"At line {i+1}, random should generate uint value {uintValue}"); } } else if (lines[i].StartsWith("Longs")) { random = new XoShiRo256StarStar(seed.ToArray()); while ((ulongValue = lines[++i].Replace("0x", "").ParseToULong(NumberStyles.HexNumber, CultureInfo.CurrentCulture)) != null) { random.NextULong().Should().Be(ulongValue.Value, $"At line {i+1}, random should generate ulong value {ulongValue}"); } } else if (lines[i].StartsWith("Floats")) { random = new XoShiRo256StarStar(seed.ToArray()); while ((floatValue = lines[++i].ParseToFloat()) != null) { random.NextFloat().Should().BeApproximately(floatValue.Value, float.Epsilon, $"At line {i+1}, random should generate float value {floatValue}"); } } else if (lines[i].StartsWith("Doubles")) { random = new XoShiRo256StarStar(seed.ToArray()); while ((doubleValue = lines[++i].ParseToDouble()) != null) { random.NextDouble().Should().BeApproximately(doubleValue.Value, double.Epsilon, $"At line {i+1}, random should generate double value {doubleValue}"); } } else if (lines[i].StartsWith("Bytes")) { random = new XoShiRo256StarStar(seed.ToArray()); var expectedBytes = new List <byte>(); while ((byteValue = lines[++i].Replace("0x", "").ParseToByte(NumberStyles.HexNumber, CultureInfo.CurrentCulture)) != null) { expectedBytes.Add(byteValue.Value); } var randomBytes = new byte[expectedBytes.Count]; random.FillBytes(randomBytes); randomBytes.Should().BeEquivalentTo(expectedBytes); } } }