rand() gives the same values in each run

조회 수: 3 (최근 30일)
Hamza Belm
Hamza Belm 2020년 8월 3일
댓글: Steven Lord 2020년 8월 4일
Hi
I'm working on the evaluation of metaheuristic algorithms and i need to test each technique in many runs, however the rand() function always generates the same random values in each run, which is not good for the evaluation.
For example, if rand()=0.56 in the 1st run at the 2nd iteration, then rand()=0.56 for all the other runs at the second iteration.
  댓글 수: 2
Rik
Rik 2020년 8월 3일
Does your code set a random seed anywhere?
Hamza Belm
Hamza Belm 2020년 8월 3일
I didn't use rng anywere in my code, i've just used rand() by default directly.
here is an example
v(u)= w*v(u)+(c1*rand()*(pbest(u)-dcur(u)))+(c2*rand()*(gbest-dcur(u)));
this is the only line where rand() is used

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2020년 8월 3일
Are you initializing the random number generator with rng too frequently or in the wrong place in your code flow?
  댓글 수: 2
Hamza Belm
Hamza Belm 2020년 8월 3일
I didn't use rng anywere in my code, i've just used rand() by default directly.
here is an example
v(u)= w*v(u)+(c1*rand()*(pbest(u)-dcur(u)))+(c2*rand()*(gbest-dcur(u)));
this is the only line where rand() is used
Steven Lord
Steven Lord 2020년 8월 4일
Show a full (small) segment of code that we can run that demonstrates the behavior you described.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by