Why does rand return the same output every time?

1 回表示 (過去 30 日間)
Cuong
Cuong 2017 年 5 月 18 日
コメント済み: Peter Perkins 2017 年 5 月 18 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2017 年 5 月 18 日
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 2017 年 5 月 18 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by