Random Extensions.Get Items Without Replacement Method
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.4
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.4
Overload List
Get | Creates an array populated with items chosen at random from the provided set of choices without replacement. |
Get | Creates an array populated with items chosen at random from the provided set of choices without replacement. |
Get | Populates the specified span with items chosen at random from the provided set of choices without replacement. |
GetItemsWithoutReplacement<T>(Random, T[], Int32)
Creates an array populated with items chosen at random
from the provided set of choices without replacement.
public static T[] GetItemsWithoutReplacement<T>(
this Random random,
T[] choices,
int length
)
Parameters
- random Random
- A random number generator used to generate the samples.
- choices T[]
- The items to use to populate the array.
- length Int32
- The length of the array to return.
Type Parameters
- T
- The type of the elements of choices.
Return Value
T[]An array of length elements chosen from choices.
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).Exceptions
Argument | random is null. -or- choices is null. |
Argument | choices is empty. |
Argument | length is less than zero. |
GetItemsWithoutReplacement<T>(Random, ReadOnlySpan<T>, Int32)
Creates an array populated with items chosen at random
from the provided set of choices without replacement.
public static T[] GetItemsWithoutReplacement<T>(
this Random random,
ReadOnlySpan<T> choices,
int length
)
Parameters
- random Random
- A random number generator used to generate the samples.
- choices ReadOnlySpan<T>
- The items to use to populate the array.
- length Int32
- The length of the array to return.
Type Parameters
- T
- The type of the elements of choices.
Return Value
T[]An array of length elements chosen from choices.
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).Exceptions
Argument | random is null. |
Argument | choices is empty. |
Argument | length is less than zero. |
GetItemsWithoutReplacement<T>(Random, ReadOnlySpan<T>, Span<T>)
Populates the specified span with items chosen at random
from the provided set of choices without replacement.
public static void GetItemsWithoutReplacement<T>(
this Random random,
ReadOnlySpan<T> choices,
Span<T> destination
)
Parameters
- random Random
- A random number generator used to generate the samples.
- choices ReadOnlySpan<T>
- The items to use to populate the span.
- destination Span<T>
- The span to be filled with items.
Type Parameters
- T
- The type of the elements of choices.
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).Exceptions
Argument | random is null. |
Argument | choices is empty. |