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?

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random 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