Random.GetItems Method

Definition

Overloads

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

Creates an array populated with items chosen at random from the provided set of 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>(T[], Int32)

Creates an array populated with items chosen at random from the provided set of choices.

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

Source:
Random.cs
Source:
Random.cs

Creates an array populated with items chosen at random from the provided set of choices.

public:
generic <typename T>
 cli::array <T> ^ GetItems(ReadOnlySpan<T> choices, int length);
public T[] GetItems<T> (ReadOnlySpan<T> choices, int length);
member this.GetItems : ReadOnlySpan<'T> * int -> 'T[]
Public Function GetItems(Of T) (choices As ReadOnlySpan(Of T), length As Integer) As T()

Type Parameters

T

The type of array.

Parameters

choices
ReadOnlySpan<T>

The items to use to populate the array.

length
Int32

The length of array to return.

Returns

T[]

An array populated with random items.

Exceptions

choices is empty.

length is not zero or a positive number.

Remarks

The method uses Next(Int32) to select items randomly from choices by index. This is used to populate a newly-created array.

Applies to

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

Source:
Random.cs
Source:
Random.cs

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

public:
generic <typename T>
 void GetItems(ReadOnlySpan<T> choices, Span<T> destination);
public void GetItems<T> (ReadOnlySpan<T> choices, Span<T> destination);
member this.GetItems : ReadOnlySpan<'T> * Span<'T> -> unit
Public Sub GetItems(Of T) (choices As ReadOnlySpan(Of T), destination As Span(Of T))

Type Parameters

T

The type of span.

Parameters

choices
ReadOnlySpan<T>

The items to use to populate the span.

destination
Span<T>

The span to be filled with items.

Exceptions

choices is empty.

Remarks

The method uses Next(Int32) to select items randomly from choices by index and populate destination.

Applies to

GetItems<T>(T[], Int32)

Source:
Random.cs
Source:
Random.cs

Creates an array populated with items chosen at random from the provided set of choices.

public:
generic <typename T>
 cli::array <T> ^ GetItems(cli::array <T> ^ choices, int length);
public T[] GetItems<T> (T[] choices, int length);
member this.GetItems : 'T[] * int -> 'T[]
Public Function GetItems(Of T) (choices As T(), length As Integer) As T()

Type Parameters

T

The type of array.

Parameters

choices
T[]

The items to use to populate the array.

length
Int32

The length of array to return.

Returns

T[]

An array populated with random items.

Exceptions

choices is empty.

choices is null.

length is not zero or a positive number.

Remarks

The method uses Next(Int32) to select items randomly from choices by index. This is used to populate a newly-created array.

Applies to