Matlab: Array of random integers with no direct repetition
问题 For my experiment I have 20 categories which contain 9 pictures each. I want to show these pictures in a pseudo-random sequence where the only constraint to randomness is that one image may not be followed directly by one of the same category. So I need something similar to r = randi([1 20],1,180); just with an added constraint of two numbers not directly following each other. E.g. 14 8 15 15 7 16 6 4 1 8 is not legitimate, whereas 14 8 15 7 15 16 6 4 1 8 would be. An alternative way I was