I'm a big fan of using Isaac64 here and there in my projects, and this one is designed to be super easy to use.
Rng()
: RNG seeded with 2048 bytes from the system's crypto RNGRng(bool)
: unseeded RNG suitable for verifying against the specRng(byte[], bool = false)
: RNG seeded with a byte array containing up to 2048 bytesRng(ulong[], bool = false)
: RNG seeded with an array of up to 256 ulongsRng(ulong, bool = false)
: RNG seeded with a single UInt64 number > 0
These constructors will throw exceptions if used unseeded (0 or empty arrays), or if the passed arrays exceed the prescribed size limits (no silent ignore). The flags are provided to allow overriding this behavior should your use case require it, or if you wish to test for standards conformance.
RandN(_size_ Max)
, where N is 64/32/16/8. These methods return unsigned integers of the corresponding size in the range [0, Max]RangedRandN(_size_ Min, _size_ Max)
methods return unsigned integers in the range [Min, Max]; theRangedRandNS(_size_ Min, _size_ Max)
variants return signed integers insteadRandAlphaNum(bool Upper, bool Lower, bool Numeric)
generates a char using the range(s) specifiedRandDouble()
returns a 64-bit double-precision float in the range (0.0, 1.0)RandDoubleRaw(double Min, double Max, double MinZero = 1e-3)
generates a double in the range (Min, Max) using the MinZero parameter as the defacto smallest number (see source for info)Shuffle()
mixes & rotates the data and refills the RNG buffer (occurs automatically at mod 256 runs)Reseed()
reseeds the RNG from ground zero at any time; has variants mirroring the class constructors
When pulling a data type smaller than 64-bits, the remaining bytes of the 8-byte chunk are banked until you request that same type size again.
All doubles pull a 64-bit integer for the mantissa/fraction. Regular doubles may also pull up to two 16-bit integers, one for the sign and one for the exponent. If the specified Min & Max are the same sign, no integer is pulled. Likewise, if Min & Max share a common exponent, no integer will be pulled. Subnormal doubles (extremely small < 10^-308) will never pull an integer for their exponent, and may or may not pull an integer for their sign, exactly the same as regular doubles.
- Verified against Bob Jenkins' original C reference implementation: ISAAC64
- Verified both seeded and unseeded tests (32 & 64-bit) with the Rust core library: Rust Core Lib
- Verified with the Zig std library's Isaac64 crypto provider: Zig Std
This builds on the newest .NET 8 RC2 (October 2023) in the AOT build configuration, and nothing is too fancy. It should build going pretty far back in the C# lineage if required.
If there are any bugs or diversions from the spec, please reach out.