Returns a random permutation of integers. randperm2(n) is a random permutation of the integers from 1 to n. For example, randperm2(6) might be [2 4 5 6 1 3]. randperm2(n,k) is only returns the first k elements of the permuation, so for example randperm2(6) might be [2 4]. This is a faster version of randperm.m if only need first k<<n elements of the random permutation. Also uses less random bits (only k). Note that this is an implementation O(k), versus the matlab implementation which is O(nlogn), however, in practice it is often slower for k=n because it uses a loop. INPUTS n - permute 1:n k - keep only first k outputs OUTPUTS p - k length vector of permutations EXAMPLE randperm2(10,5) DATESTAMP 29-Sep-2005 2:00pm See also RANDPERM