Documentation

This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

randperm

Random permutation

Syntax

`p = randperm(n)p = randperm(n,k)`

Description

`p = randperm(n)` returns a row vector containing a random permutation of the integers from 1 to `n` inclusive.

`p = randperm(n,k)` returns a row vector containing `k` unique integers selected randomly from 1 to `n` inclusive.

Examples

`randperm(6)`
might be the vector
`[3 2 6 4 1 5]`
or it might be some other permutation of the integers from 1 to 6, depending on the state of the random number generator. Two successive calls to `randperm` would in most cases return two different vectors:
```randperm(6) ans = 5 2 6 4 1 3 randperm(6) ans = 4 1 6 2 3 5```

` randperm(6,3)`
might be the vector
`[4 2 5]`
or it might be some other permutation of any three integers from 1 to 6 inclusive, depending on the state of the random number generator.

collapse all

Tips

For `p = randperm(n,k)`, `p` contains `k` unique values. `randperm` performs k-permutations (sampling without replacement). To allow repeated values in the output (sampling with replacement), use `randi(n,1,k)`.

`randperm` uses the same random number generator as `rand`, `randi`, and `randn`. You control this generator with `rng`.