## Random permutation matrix of order n

from PyECC import *


'''
The permutation matrix associated to a permutation  {0,1,...,n-1}
is constructed, starting with the zero matrix P of order n with
integer entries, with the assignments 
   P[j,p[j]] = 1 
for j = 0,1,...,n-1.
   If the permutation is chosen at random, then we get a 
random permutation matrix.
'''

def rd_permutation_matrix(n):
    N = list(range(n))
    p = rd_permutation(n)
    P = matrix(ZZ(),n,n)		
    for j in range(n):
        P[j,p[j]] = 1
    return P

P = rd_permutation_matrix(5)

show(P)

# The determinant of P is 1 if the permutation p is even and -1 if it is odd.

show('det(P) :', det(P))