Randomly generated numbers do not change themselves with each iteration
2 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I have a long code and at the end of it I reach a maximum values using tons of randomly generated numbers and distribution method. Now, I want to put this whole code into for loop and for each iteration, since those random number generation functions will generate different numbers in each iterations, I want to obtain different maximum values. I simply added a "for l=1:4" at the beginning and at the end, I added Maxx(l)=max(Difference).There, "difference" is (1000,1) vector for 1000 randomly generated numbers. Instead of obtaining 4 different max result caused from different random number generation, I got same result every iteration. What might be the reason and how can I solve this? Thank you for your help.
0 件のコメント
回答 (1 件)
the cyclist
2022 年 6 月 8 日
Can you post your code? This miniature version of what you described seems to work.
rng default
format long
for l = 1:4
difference = rand(1000,1);
maxx(l) = max(difference);
end
maxx
Or maybe it only seemed that your values were not different, because you did not display with enough digits?
2 件のコメント
the cyclist
2022 年 6 月 9 日
You set
rng('default');
at the beginning of each loop. That means that each loop starts from the same random number generator seed. You should pull that line outside of the loop, as it is in my example.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!