mardi 21 juillet 2020

Generate the same result using random number generator

I have code that uses the random number generator at the beginning of the file. The 'rng(x)' function is in a for loop where 'x' is the different seeds that I use to generate different numbers. Let's say that 'x' is from 1 to 10. Every time I run the code, it is supposed to generate the same random numbers,apply some operations on the numbers and generate the same results. However, each time I run the code I get different results. What could be the problem? I am using MATLAB R2017a.

for x=1:10
 rng(x)
 d=rand(5,1);
 some operations and rand is used at other places as well within the loop
end

Thank you.




Aucun commentaire:

Enregistrer un commentaire