Explain this one line of code
이전 댓글 표시
Hi,
Can anyone explain to me this one line, what actually this one line do ?
rand('state',sum(100*clock)); % resetting of the random table
채택된 답변
추가 답변 (2개)
Ben11
2014년 7월 7일
0 개 추천
I think this ensures that random numbers generated from different calls are all different since you use the current date/time in your call. You might want to take a look at this:
in which The Mathworks discourages using this syntax and proposes alternatives.
Shashank Prasanna
2014년 7월 7일
편집: Shashank Prasanna
2014년 7월 7일
Aftab, Random number generators are really pseudorandom (deterministic). This means for a given "seed" you can consistently regenerate the same sequence. This is useful if you want to re-run your experiment or perform multiple experiments on the same random stream.
In short, yes, using clock to reset the seed with generate a different stream each time since the clock is different each moment. However the recommended way to change the seed is to use the RNG function:
rng('shuffle')
Also all the link provided by SS and Ben are relevant.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!