MATLAB Answers

Why do I get identical outputs from a randomized script?

1 view (last 30 days)
Destiny Ellenor
Destiny Ellenor on 28 Oct 2020
Answered: Peter Perkins on 19 Nov 2020
Hi all,
I am working on writing a script to simulate the random motion and decay of particles (random-walk). However, despite the fact that I call:
rng('shuffle');
at the beginnning of the script (after I call the function w/ input arguments), I have been getting the exact same output vectors from different/separate runs. rand and exprnd are both called within the script.
Should I make this the first line of the script instead? Or has anyone else had issues with this?

  1 Comment

Destiny Ellenor
Destiny Ellenor on 28 Oct 2020
UPDATE**
I am submittng the scripts to a remote cluster using SLURM workload manager in LINUX. With this, I submit several jobs that are queued. I think some of these jobs may be submitted at the same time, and from what I have been reading, rng('shuffle') is dependent on the date and time that it is called. So becuase some of the scripts are submitted at the same time, they end up with the same seed.
However, I do not know how to fix this. Is there a way to either ensure different seeds are selected OR ensure SLURM jobs are not submitted at the same time?
Thank you in advance.

Sign in to comment.

Answers (1)

Peter Perkins
Peter Perkins on 19 Nov 2020
You don't want to use seeds to get independent parallel random number streams. Switch to using one of the generators that is designed for parallel random number generation, and use separate streams or substreams.

  0 Comments

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!