ListExt.RandomElementsWithoutRepetitionExcept<T> Method

Returns a list with n random elements from a list without repetition. An additional list can be provided to exclude elements from appearing in the results.

Namespace: UltimateXR.Extensions.System.Collections
Assembly: UltimateXR (in UltimateXR.dll) Version: 0.0.0.0

Syntax

C#

public static List<T> RandomElementsWithoutRepetitionExcept<T>(
	this IReadOnlyList<T> self,
	IReadOnlyList<T> listToExclude,
	int count
)

Parameters

 

self
Type: System.Collections.Generic.IReadOnlyList<T>
List to get the random elements from
listToExclude
Type: System.Collections.Generic.IReadOnlyList<T>
List of elements to exclude from the results
count
Type: System.Int32
Number of random elements to get

Type Parameters

 

T
Element type

Return Value

Type: List<T>
List with random elements. If count is larger than the list, the result list will be as long as the input list minus the excluded elements.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadOnlyList<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

Uses Unity’s random number generator (Range(Int32, Int32)).

See Also

Reference

ListExt Class
UltimateXR.Extensions.System.Collections Namespace