Wintellect.PowerCollections Namespace
Algorithms Class
Algorithms Methods
GhostDoc Pro Sample Help File

Algorithms..::..RandomSubset<(Of <(<'T>)>)> Method (IEnumerable<(Of <(<'T>)>)>, Int32)

Picks a random subset of count items from collection, and places those items into a random order. No item is selected more than once.

Namespace:  Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax


public static T[] RandomSubset<T>(
	IEnumerable<T> collection,
	int count
)
Public Shared Function RandomSubset(Of T) ( _
	collection As IEnumerable(Of T), _
	count As Integer _
) As T()
public:
generic<typename T>
static array<T>^ RandomSubset(
	IEnumerable<T>^ collection, 
	int^ count
)

Type Parameters

T
The type of items in the collection.

Parameters

collection
Type: IEnumerable<(Of <(<'T>)>)>
The collection of items to select from. This collection is not changed.
count
Type: Int32
The number of items in the subset to choose.

Return Value

An array of count items, selected at random from collection.

Exceptions


ExceptionCondition
ArgumentOutOfRangeExceptioncount is negative or greater than collection.Count.

Remarks


If the collection implements IList<T>, then this method takes time O(count). Otherwise, this method takes time O(N), where N is the number of items in the collection.