Combinatorics Class |
public static class Combinatorics
The Combinatorics type exposes the following members.
Name | Description | |
---|---|---|
Combinations | Count the number of possible combinations without repetition. The order does not matter and each object can be chosen only once. | |
CombinationsWithRepetition | Count the number of possible combinations with repetition. The order does not matter and an object can be chosen more than once. | |
GenerateCombination(Int32, Random) | Generate a random combination, without repetition, by randomly selecting some of N elements. | |
GenerateCombination(Int32, Int32, Random) | Generate a random combination, without repetition, by randomly selecting k of N elements. | |
GenerateCombinationWithRepetition | Generates a random combination, with repetition, by randomly selecting k of N elements. | |
GeneratePermutation | Generate a random permutation, without repetition, by generating the index numbers 0 to N-1 and shuffle them randomly. Implemented using Fisher-Yates Shuffling. | |
GenerateVariation(BigInteger, Int32, Random) |
Generate a random variation, without repetition, by randomly selecting k of n elements with order. This is an O(k) space-complexity implementation optimized for very large N. The space complexity of Fisher-Yates Shuffling is O(n+k). When N is very large, the algorithm will be unexecutable in limited memory, and a more memory-efficient algorithm is needed. You can explicitly cast N to BigInteger if N is out of range of Int32 or memory, so that this special implementation is called. However, this implementation is slower than Fisher-Yates Shuffling: don't call it if time is more critical than space. The K of type BigInteger seems impossible, because the returned array is of size K and must all be stored in memory. | |
GenerateVariation(Int32, Int32, Random) | Generate a random variation, without repetition, by randomly selecting k of n elements with order. Implemented using partial Fisher-Yates Shuffling. | |
GenerateVariationWithRepetition | Generate a random variation, with repetition, by randomly selecting k of n elements with order. | |
Permutations | Count the number of possible permutations (without repetition). | |
SelectCombinationT | Select a random combination, without repetition, from a data sequence by selecting k elements in original order. | |
SelectCombinationWithRepetitionT | Select a random combination, with repetition, from a data sequence by selecting k elements in original order. | |
SelectPermutationT | Select a random permutation from a data sequence by returning the provided data in random order. Implemented using Fisher-Yates Shuffling. | |
SelectPermutationInplaceT | 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. | |
SelectVariationT | Select a random variation, without repetition, from a data sequence by randomly selecting k elements in random order. Implemented using partial Fisher-Yates Shuffling. | |
SelectVariationWithRepetitionT | Select a random variation, with repetition, from a data sequence by randomly selecting k elements in random order. | |
Variations | Count the number of possible variations without repetition. The order matters and each object can be chosen only once. | |
VariationsWithRepetition | Count the number of possible variations with repetition. The order matters and each object can be chosen more than once. |