randperm

Generates a random permutation vector.

Syntax

v = randperm(n)

v = randperm(n, m)

Inputs

n
The number of elements to permute: [1:n].
Type: integer
Dimension: scalar
m
The number of unique elements ≤ n to select (default: n).
Type: integer
Dimension: scalar

Outputs

v
A random permutation vector.

Examples

Randomly permute the vector [1:10].

rand('seed', 2021);
v = randperm(10)
v = [Matrix] 1 x 10
7  9  8  1  5  2  3  10  4  6

Randomly select 7 elements from the vector [1:10].

rand('seed', 2021);
v = randperm(10, 7)
v = [Matrix] 1 x 7
7  9  8  1  5  2  3