Random Interop Extensions.As Random Method
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
Overload List
| AsRandom( | Converts a random source to a Random. |
| AsRandom<T>(T) | Converts a typed random source to a Random. |
AsRandom<T>(T)
public static Random AsRandom<T>(
this T randomSource
)
where T : class, IRandomSource
Parameters
- randomSource T
- The random source to convert.
Type Parameters
- T
- The random source type, which must be a class implementing IRandomSource.
Return Value
RandomA Random that delegates to randomSource.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type T. 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 randomSource in a Random adapter for use in BCL APIs. The wrapper forwards all operations to the underlying random source.
This generic overload preserves the exact type T, enabling precise type recovery via TryUnwrap<T>(Random, T).
No Caching:
Repeated calls may allocate new wrapper instances. Do not rely on wrapper identity or equality.
Round-tripping:
Calling TryUnwrap<TRng>() on the returned Random recovers the original randomSource instance.
Exceptions
| Argument | randomSource is null. |
AsRandom(IRandomSource)
public static Random AsRandom(
this IRandomSource randomSource
)Parameters
- randomSource IRandomSource
- The random source to convert.
Return Value
RandomA Random that delegates to randomSource.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IRandomSource. 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 randomSource in a Random adapter for use in BCL APIs. The wrapper forwards all operations to the underlying random source.
No Caching:
Repeated calls may allocate new wrapper instances. Do not rely on wrapper identity or equality.
Round-tripping:
Calling AsRandomSource() on the returned Random recovers the original randomSource instance.
Exceptions
| Argument | randomSource is null. |