FUNCTION REFERENCE

randperm

Random permutation.

Random permutation.

Syntax

p = randperm(n)

Syntax

p = randperm(n, k)

A row of k distinct integers from 1 to n in random order (k = n by default).

It uses the same stream as rand, so rng(s) makes it repeatable. randperm(n) sorts

n uniform draws. randperm(n,k) samples without replacement; it consumes k draws

when k < n/4, 2*k draws when n/4 <= k < n, and n-1 draws when k = n > 0.

Example

sort(randperm(5))   % [1 2 3 4 5]

Differences from MATLAB: n is capped by MatRust's matrix element limit. Seeded

sequences are not guaranteed to equal MATLAB's for every seed and size.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.