MATLAB: How to generate k unique random numbers from 1 to n in matlab 2009

MATLABrandom number generator

Hi, I knew randperm(n,k) works but this is after 2011. Can some one tell me if there is any efficient way to do it in matlab 2009.
Thanks

Best Answer

[idx,idx]=sort(rand(1,n));
out=idx(1:k)