nebulae.rng
0.8.1
See the version list below for details.
dotnet add package nebulae.rng --version 0.8.1
NuGet\Install-Package nebulae.rng -Version 0.8.1
<PackageReference Include="nebulae.rng" Version="0.8.1" />
<PackageVersion Include="nebulae.rng" Version="0.8.1" />
<PackageReference Include="nebulae.rng" />
paket add nebulae.rng --version 0.8.1
#r "nuget: nebulae.rng, 0.8.1"
#addin nuget:?package=nebulae.rng&version=0.8.1
#tool nuget:?package=nebulae.rng&version=0.8.1
nebulae-random
A collection of random number generators for most every need.
Implements a common interface for random number generation, similar to the older ISAAC64 library. The goal is to provide a simple and consistent interface for generating random numbers, no matter what the underlying generator is.
This library implements the following generators:
- ISAAC64
- Xoshiro128+
- Xoshiro128++
- Xoshiro128**
- Xoshiro256+
- Xoshiro256++
- Xoshiro256**
- Xoshiro512+
- Xoshiro512++
- Xoshiro512**
- Xoshiro1024++
- Xoshiro1024*
- Xoshiro1024**
- Mersenne Twister (MT19937) 32-bit
- Mersenne Twister (MT19937) 64-bit
- PCG32
- MWC128
- MWC192
- MWC256
- GMWC128(*)
- GMWC256
- Splitmix64
Each generator is seeded slightly differntly, but there is a common interface for all of them. Most can be seeded with 1, 2 or 3 64-bit unsigned integers, and all provide a default constructor that will seed them using the system's cryptographic rng.
(*) GMWC128 does not support LongJump() in this implementation- there was a disagreement over the sequence generated between the original C code, the C++ code using the Boost MPC library and the C# code, so I left that functionality out. Jump() is still supported, however.
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.
Methods:
The RangedRandN{S} functions support bias elimination via modulo sampling; more than one random may be burned in these functions if the generated number falls outside the mod range.
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, char[]? symbols)
generates a char using the range(s) specified, optionally also using the symbols array if provided (bias is eliminated in all cases)RandDouble()
returns a 64-bit double-precision float in the range [0.0, 1.0)RandDoubleRaw(double Min, double Max, double MinZero = 1e-4)
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 constructorsClone()
returns a new instance of the Rng with a complete clone of the current RNG's state; this allows you to "fork" the RNG and run multiple independent RNGs, all of which will start with identical state from the point of Clone(). Useful for using the same RNG state in multiple functions or threads.Jump()
jumps the rng sequence ahead (usually by 2^64 or more) for parallel simulations using the same seed. Not supported by all generators.LongJump()
jumps the rng sequence ahead (usually by 2^128 or more) for parallel simulations using the same seed. Not supported by all generators.
Mimic of System.Random for 32-bit Ints:
Next()
: returns a 32-bit unsigned integer in the range [0, 2^32)Next(int Max)
: returns a 32-bit unsigned integer in the range [0, Max)Next(int Min, int Max)
: returns a 32-bit unsigned integer in the range [Min, Max)NextDouble()
: returns a 64-bit double precision floating point value in the range [0.0, 1.0)
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.
Notes on Random Doubles:
All doubles pull a 64-bit integer for the mantissa/fraction. Regular doubles may also pull a 16-bit integer for the sign bit and one 32-bit integer 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.
Etc:
If there are any bugs or diversions from the specs, please reach out.
N
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.