How do I randomize a sequence of random numbers?
15 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Shunichi Kusano
on 21 Feb 2019
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?
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!