Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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?

Risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by