You can use the randperm
function which generates a random permutation without repeat of the numbers.
For example P = randperm(N,K)
gives K unique, non repeating numbers between 1 and N
randperm(10,5)
gives me:
9 2 1 6 5
randperm(10,10)
gives me:
7 9 4 8 2 3 6 5 1 10
Lets say you have a cell array
C = {'only','mad','dogs','and','englishmen','go','out','in','the','midday','sun'}
Then you could generate a set of random phrases without repeating tokens like this
output=[];
for i=1:5
output = [output;sprintf('%s ',C{randperm(length(C))})];
end
which gives me an output like the following
out only dogs in mad englishmen sun go and midday the
in and the midday sun only englishmen out go dogs mad
out midday go in dogs and only englishmen the mad sun
the sun out mad midday englishmen go only and dogs in
midday mad sun out dogs in and go englishmen the only