RandomInteropExtensions.AsRandomSource Method

Converts a Random to a random source.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public static IRandomSource AsRandomSource(
	this Random random
)

Parameters

random  Random
The Random to convert.

Return Value

IRandomSource
An IRandomSource that delegates to random.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method wraps random in a Numerics.NET IRandomSource adapter for use in Numerics.NET APIs. The wrapper forwards all operations to the underlying Random instance.

No Caching:

Repeated calls may allocate new wrapper instances. Do not rely on wrapper identity or equality.

Round-tripping:

If random is a WrappedIRandom<TRng>, this method returns the original underlying random source.

State Persistence:

The returned wrapper does not support state persistence. Calling state-related members on the wrapper throws NotSupportedException.

Exceptions

ArgumentNullExceptionrandom is null.

See Also