Random permutation of integers
The sequence of numbers produced byrandperm
is determined by the internal settings of the uniform pseudorandom number generator that underliesrand
,randi
,randn
, andrandperm
. To control that shared random number generator, use therng
function.
The arrays returned byrandperm
contain permutation of integers without repeating integer values. This behavior is sometimes referred to as sampling without replacement. If you require repeating values, use therandi
function.
randperm(n)
和randperm(n,n)
both generate permutations of the integers 1 throughn
, but they can give different random orderings in the permutations. For largen
,randperm(n,n)
is faster thanrandperm(n)
.