Namespaces

Types in MathNet.Numerics

Type Combinatorics

Namespace MathNet.Numerics

Enumerative Combinatorics and Counting.

Static Functions

Public Static Functions

double Combinations(int n, int k)

Count the number of possible combinations without repetition. The order does not matter and each object can be chosen only once.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen at most once.

Return
double

Maximum number of combinations.

double CombinationsWithRepetition(int n, int k)

Count the number of possible combinations with repetition. The order does not matter and an object can be chosen more than once.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen 0, 1 or multiple times.

Return
double

Maximum number of combinations with repetition.

Boolean[] GenerateCombination(int n, Random randomSource)

Generate a random combination, without repetition, by randomly selecting some of N elements.
Parameters
int n

Number of elements in the set.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Boolean[]

Boolean mask array of length N , for each item true if it is selected.

Boolean[] GenerateCombination(int n, int k, Random randomSource)

Generate a random combination, without repetition, by randomly selecting k of N elements.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen at most once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Boolean[]

Boolean mask array of length N , for each item true if it is selected.

Int32[] GenerateCombinationWithRepetition(int n, int k, Random randomSource)

Generates a random combination, with repetition, by randomly selecting k of N elements.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Elements can be chosen more than once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Int32[]

Integer mask array of length N , for each item the number of times it was selected.

Int32[] GeneratePermutation(int n, Random randomSource)

Generate a random permutation, without repetition, by generating the index numbers 0 to N-1 and shuffle them randomly. Implemented using Fisher-Yates Shuffling.
Parameters
int n

Number of (distinguishable) elements in the set.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Int32[]

An array of length N that contains (in any order) the integers of the interval [0, N).

Int32[] GenerateVariation(int n, int k, Random randomSource)

Generate a random variation, without repetition, by randomly selecting k of n elements with order. Implemented using partial Fisher-Yates Shuffling.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen at most once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Int32[]

An array of length K that contains the indices of the selections as integers of the interval [0, N).

Int32[] GenerateVariationWithRepetition(int n, int k, Random randomSource)

Generate a random variation, with repetition, by randomly selecting k of n elements with order.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Elements can be chosen more than once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
Int32[]

An array of length K that contains the indices of the selections as integers of the interval [0, N).

double Permutations(int n)

Count the number of possible permutations (without repetition).
Parameters
int n

Number of (distinguishable) elements in the set.

Return
double

Maximum number of permutations without repetition.

IEnumerable<T> SelectCombination<T>(this IEnumerable<T> data, int elementsToChoose, Random randomSource)

Select a random combination, without repetition, from a data sequence by selecting k elements in original order.
Parameters
IEnumerable<T> data

The data source to choose from.

int elementsToChoose

Number of elements (k) to choose from the data set. Each element is chosen at most once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
IEnumerable<T>

The chosen combination, in the original order.

IEnumerable<T> SelectCombinationWithRepetition<T>(this IEnumerable<T> data, int elementsToChoose, Random randomSource)

Select a random combination, with repetition, from a data sequence by selecting k elements in original order.
Parameters
IEnumerable<T> data

The data source to choose from.

int elementsToChoose

Number of elements (k) to choose from the data set. Elements can be chosen more than once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
IEnumerable<T>

The chosen combination with repetition, in the original order.

IEnumerable<T> SelectPermutation<T>(this IEnumerable<T> data, Random randomSource)

Select a random permutation from a data sequence by returning the provided data in random order. Implemented using Fisher-Yates Shuffling.
Parameters
IEnumerable<T> data

The data elements to be reordered.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

void SelectPermutationInplace<T>(T[] data, Random randomSource)

Select a random permutation, without repetition, from a data array by reordering the provided array in-place. Implemented using Fisher-Yates Shuffling. The provided data array will be modified.
Parameters
T[] data

The data array to be reordered. The array will be modified by this routine.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

IEnumerable<T> SelectVariation<T>(this IEnumerable<T> data, int elementsToChoose, Random randomSource)

Select a random variation, without repetition, from a data sequence by randomly selecting k elements in random order. Implemented using partial Fisher-Yates Shuffling.
Parameters
IEnumerable<T> data

The data source to choose from.

int elementsToChoose

Number of elements (k) to choose from the set. Each element is chosen at most once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
IEnumerable<T>

The chosen variation, in random order.

IEnumerable<T> SelectVariationWithRepetition<T>(this IEnumerable<T> data, int elementsToChoose, Random randomSource)

Select a random variation, with repetition, from a data sequence by randomly selecting k elements in random order.
Parameters
IEnumerable<T> data

The data source to choose from.

int elementsToChoose

Number of elements (k) to choose from the data set. Elements can be chosen more than once.

Random randomSource

The random number generator to use. Optional; the default random source will be used if null.

Return
IEnumerable<T>

The chosen variation with repetition, in random order.

double Variations(int n, int k)

Count the number of possible variations without repetition. The order matters and each object can be chosen only once.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen at most once.

Return
double

Maximum number of distinct variations.

double VariationsWithRepetition(int n, int k)

Count the number of possible variations with repetition. The order matters and each object can be chosen more than once.
Parameters
int n

Number of elements in the set.

int k

Number of elements to choose from the set. Each element is chosen 0, 1 or multiple times.

Return
double

Maximum number of distinct variations with repetition.