Click or drag to resize
Accord.NET (logo)

VectorSample Method (Int32, Int32)

Returns a vector of the specified sampleSize containing non-repeating indices in the range [0, populationSize) in random order.

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
public static int[] Sample(
	int sampleSize,
	int populationSize
Request Example View Source


Type: SystemInt32
The size of the sample vector to be generated.
Type: SystemInt32
The non-inclusive maximum number an index can have.

Return Value

Type: Int32
In other words, this return a sample of size k from a population of size N, where k is the parameter sampleSize and N is the parameter populationSize.
var a = Vector.Sample(3, 10);  // a possible output is { 1, 7, 4 };
var b = Vector.Sample(10, 10); // a possible output is { 5, 4, 2, 0, 1, 3, 7, 9, 8, 6 };

foreach (var i in Vector.Sample(5, 6))
   // ...
See Also