Is there a way in Sage to generate a random permutation with a given cycle type?
This works:
sage: P = Permutations(5)
sage: p = P.random_element()
sage: p
[2, 3, 1, 5, 4]
sage: p.cycle_type()
[3, 2]
sage: p = P.random_element()
sage: p.cycle_type()
[5]
The following does not work:
sage: p = P.random_element(cycle_type=[3,2])
Is this already written elsewhere?
I don't know of a direct implementation, but you could try
T = SetPartitions(5, [3,2])
and thenT.random_element()
to get two disjoint subsets of size 2 and 3. Then form a permutation from them.conjugate any chosen permutation of the given cycle type by a random permutation
Yes, good idea, thank you both!