Repetition of random numbers for variables with different length
4 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
My code has different loops and different algorithms and I need to get always the same or part of the same sequence of random numbers. I have been used the command rng('default') or rng(0,'twister') in several parts of the code, but, unfortunatelly, it did not work.
Basically, in order to simply, I am doing a simple code below to illustrate what I am saying:
rng(0,'twister');
s=rng();
A=lhsdesign(2,2)
rng(s)
B=lhsdesign(1,2)
The results that I got are:
A =
0.021416525878527 0.099859765555600
0.757312175638579 0.929056830686392
B =
0.873013183706494 0.086624143860981
What I should expect is B equal to the first line of A. But, it is not. Why?
Could anyone help me to solve that?
Many thanks,
Odilon.
0 件のコメント
回答 (2 件)
Walter Roberson
2020 年 5 月 25 日
random number generation is done down columns, so with (2,2) the order would be
1 3
2 4
When you then use (1,2) then the second random number generated would go into making the first value of the second variable.
But you do not see A(1,1) the same as B(1,1) because the algorithm uses several iterations and additional random numbers and does not treat the columns exactly the same as rows.
2 件のコメント
Stephen23
2020 年 5 月 26 日
Odilon Rodrigues Filho's incorrectly posted "Answer" moved here:
Thank you very much, Walter.
Is there any way to make them (lhs) to be the same?
Thanks, Odilon
Stephen23
2020 年 5 月 26 日
Odilon Rodrigues Filho's incorrectly posted "Answer" moved here:
Thank you a lot, Walter, for your help. I will try to figure out how Can I solve that. Best, Odilon
Odilon Rodrigues Filho
2020 年 5 月 25 日
1 件のコメント
Walter Roberson
2020 年 5 月 25 日
No. When you ask for more than one row, the rows are selected from different ranges each, and then the rows are shuffled. The range depends on the number of rows you asked for. The result for asking for two rows is not going to be the same as asking for one row.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!