Click or drag to resize

CombinatoricsGenerateVariation(BigInteger, Int32, Random) Method

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.

Namespace: Altaxo.Calc
Assembly: AltaxoCore (in AltaxoCore.dll) Version: 4.8.3179.0 (4.8.3179.0)
Syntax
C#
public static BigInteger[] GenerateVariation(
	BigInteger n,
	int k,
	Random randomSource = null
)

Parameters

n  BigInteger
Number of elements in the set.
k  Int32
Number of elements to choose from the set. Each element is chosen at most once.
randomSource  Random  (Optional)
The random number generator to use. Optional; the default random source will be used if null.

Return Value

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