[TOC]

randperm

Random permutation

Usage

p = randperm(n)

p = randperm(n, k)

Examples

Input
% Initalize the random number generator with seed 0.
rng(0)
randperm(6)
randperm(6,5)

% Initalized with the same seed.
% randperm gives the same results as before.
rng(0)
randperm(6)
randperm(6,5)
Output
ans = 
 2.0000   6.0000   4.0000   1.0000   3.0000   5.0000

ans = 
 2.0000   4.0000   1.0000   6.0000   3.0000

ans = 
 2.0000   6.0000   4.0000   1.0000   3.0000   5.0000

ans = 
 2.0000   4.0000   1.0000   6.0000   3.0000

Discussions