フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by