function p=randperm(n) % outputs a random permutation of the integers {1,2,...,n} p=1; for i=2:n p=[p i]; k=ceil(i*rand); p([k i])=p([i k]); end