MATLAB: Could anyone help me how to solve the following issue.

randi

I am using the command line
randi([1,5], 1, 10)
to generate numbers with respect to single row versus 10 columns.
when i run the command sometimes it generates all 5 numbers with respect to single row versus 10 columns in the following manner
3 1 2 1 1 4 4 5 2 5
sometimes it doesnt and i am getting the result as follows:
4 1 5 5 5 1 1 2 2 4(number 3 is missing)
But for me i want to have all 5 number every time when the command executes.Could anyone please help me on this.

Best Answer

I can't think of a better solution, but you could try brute-forcing it with a while loop:
maxval=5;cols=10;
if maxval>cols
error('impossible combination')
end
result=randi(maxval,1,cols);
val_list=1:maxval;
while ~all(ismember(val_list,result))
result=randi(maxval,1,cols);
end