RandomNumberGenerator.GetItems Method

Definition

Overloads

GetItems<T>(ReadOnlySpan<T>, Int32)

Creates an array populated with items chosen at random from choices.

GetItems<T>(ReadOnlySpan<T>, Span<T>)

Fills the elements of a specified span with items chosen at random from the provided set of choices.

GetItems<T>(ReadOnlySpan<T>, Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

Creates an array populated with items chosen at random from choices.

C#
public static T[] GetItems<T>(ReadOnlySpan<T> choices, int length);

Type Parameters

T

The type of items.

Parameters

choices
ReadOnlySpan<T>

The items to use to populate the array.

length
Int32

The length of array to return populated with items.

Returns

T[]

An array populated with random choices.

Exceptions

choices is empty.

length is not zero or a positive number.

Applies to

.NET 10 and other versions
Product Versions
.NET 8, 9, 10

GetItems<T>(ReadOnlySpan<T>, Span<T>)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

Fills the elements of a specified span with items chosen at random from the provided set of choices.

C#
public static void GetItems<T>(ReadOnlySpan<T> choices, Span<T> destination);

Type Parameters

T

The type of items.

Parameters

choices
ReadOnlySpan<T>

The items to use to fill the buffer.

destination
Span<T>

The buffer to receive the items.

Exceptions

choices is empty.

Applies to

.NET 10 and other versions
Product Versions
.NET 8, 9, 10