Direct link to this comment

Similar question: I am creating a SimEvents model programmatically and repeatedly running it multiple times from a script that executes the following sequence: rng(x);sim(xxx) where x is the number of the simulation being run (and xxx is all the parameters that sim requires). I find that all simulations give the same result, apparently ignoring the rng(x) command given just prior to each simulation made with sim(xxx). Does sim(xxx) ignore the current seed and reinitialize the random number generator? If so, how can I set a seed in a SimEvents model (which is initiated by sim(xxx))?

The PreSimFcn expects a SimulationInput object to be returned (in case any output is returned) and in this case 'rng' returns a struct causing the PreSimFcn to error out. You can achieve what you are looking for by defining a local function which does not return any output

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.