Correct way of using random number generator with multiple m files

조회 수: 3 (최근 30일)
Tan Biru
Tan Biru 2014년 10월 4일
댓글: Tan Biru 2014년 10월 5일
Dear MATLAB community,
I am using random functions like randi and rand in two functions in two different m files. These two m files with the random function is called from a main script. I would like to use random number generator rng to seed the random function. Do I use the rng at the main script or do I use it separately on the m files, which is the more proper way?
Thank you.
Regards,
Tan Biru

채택된 답변

the cyclist
the cyclist 2014년 10월 4일
It depends on the reason you are setting the seed.
Do you want the two functions to be using the same set of pseudorandom numbers? Then set the seed in both function files.
Or do you want the two functions to be using different pseudorandom numbers? Then set the seed in the main function.
  댓글 수: 1
Tan Biru
Tan Biru 2014년 10월 5일
I want the functions to use different pseudorandom numbers. I use rng only for repeatability purposes. Thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by