In R2012b I created a Stateflow chart (Matlab syntax) containing several random function calls ( rand(1,1), randn(1,1) and randi(n,1)) to model uncertainties. This works well, but each time I run a simulation, it returns exactly the same results because by default the random generator resets itself before each simulation. This is not what I want: I want to have different results every time. The Matlab function rng('shuffle') seems to be exactly what I need but it isn't compatible with Stateflow or Simulink. Typing rng('shuffle') in the Matlab command window before each simulation run doesn't work either. The only option I seem to have is to use input from Simulink Random Source blocks because they have a 'repeatability' setting. Random sources may relatively easily replace rand(1,1) or randn(1,1), but not randi(n,1). Is there a more elegant solution – preferably a way to prevent resetting of the random generator?
MATLAB: How to achieve non-repeatable randomization in Stateflow
randirandom number generatorrandom sourcerng('shuffle')simulinkstateflow
Related Question
- How to generate same set of random numbers
- Consistently generating same random sequence with for and parfor loop
- Random seed has to be an integer
- What does the “seed” parameter in Uniform Random Number generator change in the block’s behaviour
- Find a command that will generate a pseudo-random number(random number) that lies bwtween -1 and 1 drawn from uniform distribution
Best Answer