How can a generate a radom number at the time from 1 to 10!
2 ビュー (過去 30 日間)
古いコメントを表示
Hi i am trying to generate a display of a random number at the time from 1 to 10 with out repetition in a loop. Any idea ? Thanks
For example
for n= 1:s
%random selection of numbers
x=randperm(40,1)
end
Screen('CloseAll'); % close screen or end of program
some times i gent the same number!
0 件のコメント
回答 (1 件)
Image Analyst
2021 年 1 月 31 日
Try this
r = randperm(10);
for k = 1 : length(r)
fprintf('%d\n', r(k));
end
2 件のコメント
Image Analyst
2021 年 2 月 1 日
Explain why you think the numbers are not random and why one or more is a repeat.
Which number is a repeat? Because I'm not seeing it. So why are you saying it does not work?
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!