Numerics. NET. Random. Adapters Namespace
Contains adapter types for interoperability between Numerics.NET RNGs
and Random.
Remarks
The Numerics.NET.Random.Adapters namespace provides Layer 4 adapter boundaries that enable seamless integration between:
- Numerics.NET random number generators (IRandomSource)
- .NET BCL Random
Adapter Types:
- WrappedRandomSource<TRng>: Wraps a random source as a Random
- WrappedSystemRandom (internal): Wraps a Random as an IRandomSource
Usage Pattern:
Most users should use the extension methods in RandomInteropExtensions rather than constructing adapter types directly:
// Convert random source to System.Random
var numericsRng = new Pcg64(42);
System.Random sysRng = numericsRng.AsRandom();
// Convert System.Random to random source
var sysRng2 = new System.Random(42);
IRandomSource numRng = sysRng2.AsRandomSource();
// Round-trip identity preservation
var original = new Pcg64(42);
IRandomSource recovered = original.AsRandom().AsRandomSource();
// recovered is the same instance as originalImportant Notes:
- No caching guarantees: Repeated calls to adapter methods may allocate new wrappers. Do not rely on wrapper identity or equality.
- No thread-safety improvements: Wrappers inherit thread-safety characteristics from the underlying RNG.
- State preservation: Wrappers forward operations to the underlying instance, so state mutations affect the original RNG.
Classes
| Wrapped | A Random adapter over a Numerics.NET random number generator. |