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

3 visualizaciones (últimos 30 días)
MJ
MJ el 6 de Mayo de 2014
Editada: MJ el 6 de Mayo de 2014
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?

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by