function shvect=shuffle(nsamp);
%format function shvect=shuffle(nsamp);
%creates a shuffled vector of length n;
%based on Knuth (1981), as described in 
% Weir, B. S. 1990. Genetic Data Analysis
%     Sinauer, p. 298.
% written by E. Gallagher UMASS/Boston, modified 10/19/10
% Email: Eugene.Gallagher@umb.edu
% Matlab's built-in randperm.m performes the same task
% rand('uniform');
shvect=1:nsamp;
ranvec=ceil(shvect.*rand(size(shvect)));
temp=0;
for j=nsamp:-1:2
     temp=shvect(j);
     shvect(j)=shvect(ranvec(j));
     shvect(ranvec(j))=temp;
end