unrepeated integers from randi function

for the randi function for example
randi([2,6],1,4)
this basically creates 4 random integers from 2 to 6
eg. 2, 5,4,2
how can i do the same but generating unrepeated integers?
in the example the integer 2 is repeated twice and i dont want that for a randi function of a large range

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 5 月 9 日

1 投票

S = 2:6;
U = randperm(length(S));
S(U(1:4))

この質問は閉じられています。

タグ

質問済み:

2011 年 5 月 9 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by