randpermRandom permutation
p = randperm(n)1:n, where n is a real integer p = randperm(n, k)k unique integers taken from the vector 1:n, where k is an integer such that 1 <= k and k <= n hold.randperm gives the same output when the random number generator is initialized with the same seed..% Initalize the random number generator with seed 0.
rng(0)
randperm(6)
randperm(6,5)
% Initalized with the same seed.
% randperm gives the same results as before.
rng(0)
randperm(6)
randperm(6,5)
ans =
2.0000 6.0000 4.0000 1.0000 3.0000 5.0000
ans =
2.0000 4.0000 1.0000 6.0000 3.0000
ans =
2.0000 6.0000 4.0000 1.0000 3.0000 5.0000
ans =
2.0000 4.0000 1.0000 6.0000 3.0000
randperm gives the same permutation.