MATLAB: How to create random seed to have different results at each simevents run??

MATLABrandom number generatorSimEventssimulink

I would like to generate different seed at each time to have various outcomes … I have tried "shuffle," however it showed that "it is not supported!" Wish someone can help me!Thank you~
My setting is as below: (this setting makes that my simulation is always with the same outcome every time.)

Best Answer

Hi Min-Bin,
There are a couple of things you can try to vary the seed for each simulation run. It looks like you are running on Mac OS, and you can run the solution with fopen at the bottom of this response on Linux/Mac OS. On Windows, you may use the time to get the seed, which is unfortunately problematic for having multiple blocks generating random numbers.
By doing this, however, the results would be not be reproducible. We usually recommend creating a bunch of seeds at a time, caching them, and then reading from the cache, so that you can reproduce your results.
But here's a way that I hope will work for truly random results:
persistent rngInit;
if isempty(rngInit)
% only for Linux/Mac
fid = fopen('/dev/random');
rndval = fread(fid, 1, 'uint32')
fclose(fid);
seed = rndval(1);
rng(seed);
rngInit = true;
end
% Pattern: Exponential distribution
mu = 1;
dt = -mu * log(1 - rand());
-Teresa