Problem with rng shuffle

11 vues (au cours des 30 derniers jours)
Aftab Ahmed Khan
Aftab Ahmed Khan le 25 Fév 2015
Commenté : NEELU GUPTA le 24 Fév 2019
Hello everyone, I am running my simulation for like 50000 iterations but when i use
rng('shuffle')
during each iteration, the processing speed of my computer gets very slow. I want to understand that why this one line of code has so much effect on my computer ?

Réponse acceptée

Peter Perkins
Peter Perkins le 25 Fév 2015
As Sean said, don't reset the random number generator in a loop. There's no good reason to do it. You are NOT making your random number "more random", and in fact, you are likely making them less random in very complicated ways. DON'T DO THIS. I can't say that strongly enough.
'shuffle' pauses for .01s each time you call it to ensure that it uses a new seed that's different than the last time you called it. That's why it's slowing down your code.

Plus de réponses (2)

Sean de Wolski
Sean de Wolski le 25 Fév 2015
Why do you want to reset the stream on each iteration? This will be slow. The stream is random, so just set it once at the beginning of the run.
  1 commentaire
Aftab Ahmed Khan
Aftab Ahmed Khan le 25 Fév 2015
Hi, thank you for the reply but i want to understand that why it makes everything slow ?

Connectez-vous pour commenter.


Chuck
Chuck le 5 Mai 2016
I have noticed this too. Even if you do not shuffle in every generation and shuffle it once, it will be slower than rng("default"). Of course, it might be unnoticeable depending on your code.
But... We do not know the nature of your iterations. If you are using parallelization (e.g. parfor), than you need to do rng("shuffle") right after the parfor definition line. Otherwise, after each individual for loop is done, it goes back go rng("default").
If your iterations are not using parallelization, then you should be fine by just adding that at the beginning of your code.
  1 commentaire
NEELU GUPTA
NEELU GUPTA le 24 Fév 2019
Sir, How and why we use rng(shuffle), I am trying to calculate average of 2000 iterations using random number

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by