Reputation: 3783
Suppose that we have this structure:
for i=1:x1
Out = randperm(40);
Out_Final = %% divide 'Out' to 10 parts. and select these parts for some purposes
for j=1:x2
%% Process on `Out_Final`
end
end
I'm using outer loop (for i=1:x1
) to repeat main process (for j=1:x2) loop
and average between outputs to have more robust results. I want randperm
doesn't result equal (or near equal) outputs. I want have different Output for this function as far as possible in every calling in (for i=1:x1)
loop.
How can i do that in MATLAB R2014a
?
Upvotes: 0
Views: 537
Reputation: 21563
The randomness algorithms used by randperm
are very good. So, don't worry about that.
However, if you draw 10 random numbers from 1 to 10, you are likely to see some more frequently than others.
If you REALLY don't want this, you should probably not focus on randomly selecting the numbers, but on selecting the numbers in a way that they are nicely spread out througout their possible range. (This is a quite different problem to solve).
To address your comment:
The rng
function allows you to create reproducible results, make sure to check doc rng
for examples.
In your case it seems like you actually don't want to reset the rng
each time, as that would lead to correlated random numbers.
Upvotes: 1