How to pseudo-randomize the ordering of a vector?
10 views (last 30 days)
Show older comments
Say that I have a vector
A=randperm(10)
and I want to randomize the ordering of this vector. Normally I would do something like
A=Shuffle(A)
but in this case I want a pseudoradomized ordering: that is, the later the value is in A (ordering wise, not the actual content of the value), the more I want it to appear near the beginning of A. For instance, I want there to be a greater chance of values A(7:10) to appear near the front of A and the values A(1:4) to appear near the end of A. Hopefully that makes sense.
Is this possible to do?
0 Comments
Accepted Answer
Jeff Miller
on 22 Nov 2017
One approach is to think of your data, A, as being column one of a 2-column array (e.g., 10x2). Now generate pseudo-random numbers into column 2 using some scheme that tends to give smaller values to higher numbered rows, e.g.,
for iRow=1:NRows
A(iRow,2) = normrnd(-iRow,1);
end
Then, sort the rows of A by the random numbers, carrying along the data values in column 1 (see, for example, https://stackoverflow.com/questions/134712/how-can-i-sort-a-2-d-array-in-matlab-with-respect-to-one-column).
Obviously you have a lot of choices for how to assign the numbers, depending on exactly how biased you want your pseudo-random ordering to be.
0 Comments
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!