randperm
Random permutation of integers
Description
p = randperm(
returns a row vector
containing a random permutation of the integers from 1 to n
)n
without
repeating elements.
p = randperm(
generates a
random permutation of integers from random number stream s
,___)s
instead of
the default global stream. To create a stream, use RandStream
.
Specify s
followed by any of the argument combinations in previous
syntaxes.
Examples
Input Arguments
More About
Tips
The sequence of numbers produced by
randperm
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 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 therandi
function.randperm(n)
andrandperm(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)
.
Extended Capabilities
Version History
Introduced before R2006a