The problem of using rng to generate random numbers.
Mostrar comentarios más antiguos
I want to use rng to generate several random number and save the state of generating them within a loop. so at the next step, I can use this state to continue generating randome number. e.g.:
for i=1:10
if i==1
rng(1);
else
load state
end
a=rand;
b=rand;...
save state
end
Does anybody know how to programme it?
Thanks a lot
Issac
Respuestas (4)
Daniel Shub
el 11 de Abr. de 2012
Why not create a new "stream"
doc RandStream
1 comentario
X Du
el 12 de Abr. de 2012
Wayne King
el 11 de Abr. de 2012
When you call rng, you can output that information and save it if you wish
for nn = 1:10
scurr = rng;
rngstate{nn} = scurr.State;
x = randn(1,1);
end
1 comentario
X Du
el 12 de Abr. de 2012
Richard Willey
el 11 de Abr. de 2012
0 votos
It's hard to make a specific recommendation without known more about the use case.
What (specifically) are you trying to accomplish / control?
1 comentario
X Du
el 12 de Abr. de 2012
Richard Willey
el 12 de Abr. de 2012
0 votos
From the sounds of things, the simplest thing to do would be to generate all of your random numbers OUTSIDE your loop.
Start by setting your seed and generate a vector with all the random numbers that you need for all your loops. Index into this as necessary.
1 comentario
X Du
el 12 de Abr. de 2012
Categorías
Más información sobre Random Number Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!