function outdeck = shuffle(indeck, reps) % % shuffle(indeck) performs a GSR-shuffle on the elements of % the list indeck % % shuffle(indeck,reps) does this operation reps times % if nargin <=1 reps = 1; end; n = length(indeck); idx = 1:n; for k=1:reps % get n random numbers in ascending order rlist = sort(rand(1,n)); % perform shift map on each rlist = rem(2*rlist,1); % sort the list into ascending order [rlist,perm] = sort(rlist); % rearrange index list according to that sort idx = idx(perm); end; % reorder indeck accoring to idx outdeck = indeck(idx);