No, I don't think there is a faster way and I doubt it is meant to be fast. The direct and efficient way to do this would be to use randperm(10,6). The fact that you are asked to use randi instead shows that the exercise is being made artificially difficult, presumably to force you to work your coding muscles.
Best Answer