How do I randomize a sequence of random numbers?

Hi,
I've created a random sequence of numbers as shown below, but right now it just repeats the first 8 random numbers 13 times. How can I get it so that each sequence of 8 numbers is truly random from the next?
a = randi([1 4]);
b = randi([1 4]);
c = randi([1 4]);
d = randi([1 4]);
ASRTT = ([1 (a) 2 (b) 3 (c) 4 (d)]);
seqVectorX = repmat(ASRTT,1,13)';
Here's an example of the first two sequences for reference, where you can see the first 8 numbers are just starting over:
1 3 2 4 3 4 4 4 1 3 2 4 3 4 4 4
I added the line below but then it just scrambled all the numbers and didn't keep the ASRTT seqence of 1, random number, 2, random number, 3, random number, 4, random number.
seqVectorX= seqVectorX(randperm(numel(seqVectorX)));
Thanks in advance for any advice!

 採用された回答

Shunichi Kusano
Shunichi Kusano 2019 年 2 月 21 日

0 投票

repmat just repeats the input matrix. So, for what you want, the repeated matrix must change. I think the easiest way is like:
seqVectorX = [];
for i = 1:13
a = randi([1 4]);
b = randi([1 4]);
c = randi([1 4]);
d = randi([1 4]);
ASRTT = ([1 (a) 2 (b) 3 (c) 4 (d)]);
seqVectorX = [seqVectorX ASRTT];
end
And the next example makes the random numbers at first, then they are inserted to numbers in order.
v1 = repmat([1 2 3 4], 1, 13);
v2 = randi([1 4], 1,4*13); % random numbers
seqVectorX = reshape(cat(1,v1,v2),1,4*13*2);
Does this meet the objective?

1 件のコメント

Maria Y
Maria Y 2019 年 2 月 21 日
Perfect - thank you so much!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2019 年 2 月 20 日

コメント済み:

2019 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by