idxr = randi(length(a),1,10); %// create the first batch of numbers
idx = diff(idxr)==0; %// logical array, where 1s denote repetitions for first batch
while nnz(idx)~=0
idx = diff(idxr)==0; %// logical array, where 1s denote repetitions for
%// subsequent batches
rN = randi(length(a),1,nnz(idx)); %// new set of random integers to be placed
%// at the positions where repetitions have occured
idxr(find(idx)+1) = rN; %// place ramdom integers at their respective positions
end
r=a(idxr);
end