Why does rand return the same output every time?

2 visualizzazioni (ultimi 30 giorni)
Cuong
Cuong il 18 Mag 2017
Commentato: Peter Perkins il 18 Mag 2017
I am working on a research project. I downloaded a function called "astupidfunction" from authors'website and that function defines a regression model. I looked inside the function and did not see anything related to random numbers generator. What makes me surprising is that when I run the following codes thousand times
rand(1);
f=astupidfunction(x);
The rand(1) always returns the same number.
What happened when I remove the line "f=astupidfunction(x);" and run rand(1);
I obtained DIFFERENT random numbers.
I guess the reason lies on the function f=astupidfunction(x). I attached the file that contains the function "IWTGP" is the actual name of that stupid function. Anyone can help me or clarify why the above problem happened. In addition how to run
rand(1); f=astupidfunction(x);
to obtain different random numbers ?
Thanks
  2 Commenti
Geoff Hayes
Geoff Hayes il 18 Mag 2017
Cuong - have you tried contacting the author of the code? What about the EvalKernel function (defined within your attached code)? Have you looked into that function to see what it is doing?
Peter Perkins
Peter Perkins il 18 Mag 2017
That function contains no random number generator calls at all, so you're not telling the whole story.
I suggest you read the doc about rand, and controlling the random number generator, and figure out what line in your code, or whoever's code, is resetting the generator.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by