Random permutation of integers

The sequence of numbers produced by

`randperm`

is determined by the internal settings of the uniform pseudorandom number generator that underlies`rand`

,`randi`

,`randn`

, and`randperm`

. To control that shared random number generator, use the`rng`

function.The arrays returned by

`randperm`

contain permutation of integers without repeating integer values. This behavior is sometimes referred to as sampling without replacement. If you require repeating values, use the`randi`

function.`randperm(n)`

and`randperm(n,n)`

both generate permutations of the integers 1 through`n`

, but they can give different random orderings in the permutations. For large`n`

,`randperm(n,n)`

is faster than`randperm(n)`

.