Class EnumerableExtensions

Namespace
SIMDispatcher.Core.Extensions
Assembly
SIMDispatcher.Core.dll
public static class EnumerableExtensions
Inheritance
EnumerableExtensions
Inherited Members

Methods

RandomElementByWeight<T>(IEnumerable<T>, Random, Func<T, int>)

Returns a random element from the specified sequence, weighted by the provided weight selector function.

public static T? RandomElementByWeight<T>(this IEnumerable<T> sequence, Random random, Func<T, int> weightSelector)

Parameters

sequence IEnumerable<T>

The sequence from which to select a random element.

random Random

The Random instance used to generate the random index.

weightSelector Func<T, int>

A function that assigns a weight to each element in the sequence.

Returns

T

A random element from the sequence, weighted by the provided weights, or null if the sequence is empty.

Type Parameters

T

The type of elements in the sequence.

RandomElement<T>(IEnumerable<T>, Random)

Returns a random element from the specified sequence using the provided Random instance.

public static T? RandomElement<T>(this IEnumerable<T> sequence, Random random)

Parameters

sequence IEnumerable<T>

The sequence from which to select a random element.

random Random

The Random instance used to generate the random index.

Returns

T

A random element from the sequence, or null if the sequence is empty.

Type Parameters

T

The type of elements in the sequence.