Randomly sampling a given number of permutations with ot.KPermutations

I was wondering whether there is way to randomly sample a given number n of permutations of a vector when using the ot.KPermutations class, without having to generate the entire set of permutations.
For instance, if I want to generate 50 permutations of the vector containing integers ranging from 0 to 99, this cannot be done with ot.KPermutations(100).generate() as the total number of permutations to be computed seems to be too large. However, I would only need to generate a small subset of the 100! permutations, which for instance can be easily done with numpy:


Is there a similar workaround with KPermutations?


Have you try to use the KPermutationsDistribution class? Something like this:

import openturns as ot

N = 50
M = 100
N_permutations = ot.KPermutationsDistribution(M, M).getSample(N)
permuted_values = [[int(x) for x in N_permutations[j]] for j in range(N)]

The tricky part is the conversion between floats and integers, as in OT distributions produce floating point values.



I had missed the existence of the KPermutationsDistribution class. This work perfectly, thanks!
Best regards,