Why does rand return the same output every time?
2 views (last 30 days)
Show older comments
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 Comments
Geoff Hayes
on 18 May 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
on 18 May 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.
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!