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:

Adapter Types:

Usage Pattern:

Most users should use the extension methods in RandomInteropExtensions rather than constructing adapter types directly:

C#
// 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 original

Important 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

WrappedRandomSource<TRng> A Random adapter over a Numerics.NET random number generator.