Repetition of random numbers for variables with different length

4 visualizaciones (últimos 30 días)
Odilon Rodrigues Filho
Odilon Rodrigues Filho el 25 de Mayo de 2020
Comentada: Stephen23 el 26 de Mayo de 2020
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.

Respuestas (2)

Walter Roberson
Walter Roberson el 25 de Mayo de 2020
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 comentarios
Stephen23
Stephen23 el 26 de Mayo de 2020
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
Stephen23 el 26 de Mayo de 2020
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

Iniciar sesión para comentar.


Odilon Rodrigues Filho
Odilon Rodrigues Filho el 25 de Mayo de 2020
Thank you very much, Walter.
Is there any way to make them (lhs) to be the same?
Thanks, Odilon
  1 comentario
Walter Roberson
Walter Roberson el 25 de Mayo de 2020
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by