Random integer generator that stops at a certain point

11 ビュー (過去 30 日間)
Ryan Mahoney
Ryan Mahoney 2020 年 11 月 5 日
コメント済み: Ryan Mahoney 2020 年 11 月 5 日
I want to generate a random integer between 1 and 10, but I want it to keep generating integers until I get all integers between 1 and 10. Like:
r = randi( [1,10] )
4 7 2 4 9 10 8 8 5 1 6 2 7 4 4 8 3
At that point, it would stop.

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 5 日
r = [];
while length(unique(r)) ~= 10
r(end+1) = randi(10);
end
r
r = 1×20
8 3 9 4 7 3 9 4 1 2 7 6 6 5 6 2 8 7 7 10

その他の回答 (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