フィルターのクリア

Generating sets of non repeating random numbers

19 ビュー (過去 30 日間)
Toluwani Adekunle
Toluwani Adekunle 2018 年 7 月 8 日
コメント済み: Anton Semechko 2018 年 7 月 9 日
Hi,
How do I create 10 sets of random numbers within a range such that after every set, the numbers previously generated can’t be repeated or generated again i.e if I generate [1,3,8,6] from the range [1:40] those numbers would be deleted from the range and can’t be generated again

採用された回答

dpb
dpb 2018 年 7 月 8 日
編集済み: dpb 2018 年 7 月 8 日
>> ix=reshape(randperm(40),10,[])
ix =
35 23 21 40
26 17 8 36
38 5 27 18
20 10 11 9
30 33 24 28
16 25 34 15
3 12 32 7
19 37 14 13
31 4 1 2
29 39 6 22
>>

その他の回答 (1 件)

Anton Semechko
Anton Semechko 2018 年 7 月 8 日
Here is an example:
S=reshape(randperm(40),[],4);
All elements in S will be in the range [1 40] and unique. From this it follows that all 10 rows of S will also be unique.
  2 件のコメント
Toluwani Adekunle
Toluwani Adekunle 2018 年 7 月 9 日
Thanks, I have another question, what if the range of numbers I’m selecting from isn’t the same as the amount of sets I want to generate, i.e the range is 300 let’s say and I want a 27 by 9 matrix or the range is unknown
Anton Semechko
Anton Semechko 2018 年 7 月 9 日
Same idea applies, but cutoff the extraneous samples before reshaping. Example for 300 range and 27-by-9 matrix.
S=radndperm(300);
S=S(1:(27*9));
S=reshape(S,27,9);

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by