How to randomly generate an integer which is unique during multiple iterations

1 回表示 (過去 30 日間)
pavikirthi
pavikirthi 2015 年 10 月 27 日
コメント済み: pavikirthi 2015 年 10 月 27 日
How to generate a random integer in the range of 1 to 100 uniquely when the program is run and which undergoes multiple iterations? When I am using randi as follows, it is generating integer randomly but at times its not unique when the program is run in multiple iterations
index{i} = randi([1 100],1,1);

採用された回答

Jos (10584)
Jos (10584) 2015 年 10 月 27 日
You can use the function randperm for this:
N = 10
R = randperm(N)
for k=1:N
Current_Random_Integer = R(k)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by