rng is slow (to control random number generation). Can I go back to seed, or state?

조회 수: 3 (최근 30일)
MJ
MJ 2014년 5월 6일
편집: MJ 2014년 5월 6일
I've been using 'rng' to control sets of random numbers in my large simulation-optimization problem. I was trying to find speed bottlenecks in my codes using the profiler and I realized that rng is taking too much time (more than rand or randn). I then used seed and observed a huge difference between their speed. I know that MATLAB doesn't recommend using seed, state, and all those old ones...
Here's a simple test:
tic
for i=1:10000
rng(i)
rand(10,1);
end
toc
Elapsed time is 5.380547 seconds.
tic
for i=1:10000
rand('state',i)
rand(10,1);
end
toc
Elapsed time is 0.202457 seconds.
I'm using seed now and I see that it behaves strangely... I used to use state before. Can I still use that?

답변 (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