Ask Your Question

Revision history [back]

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?