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

3 次查看(过去 30 天)
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