Random "Seed"

280 views
Skip to first unread message

Ahmet Tosun

unread,
Apr 11, 2020, 10:05:58 AM4/11/20
to Jaamsim Users Discussion Group
Harry,

Is random "Seed" possible?


Ahmet Tosun

Harry King

unread,
Apr 12, 2020, 4:53:13 PM4/12/20
to Jaamsim Users Discussion Group
Ahmet,

I'm not sure what you mean. Do you mean randomly select a new seed for each random sample from a distribution? If so, there should be no need to do this. JaamSim uses the MRG random generator developed by L'Ecuyer (1999a), described in 'Simulation Modeling and Analysis 5th Ed.', Averill M. Law. (Appendix 7B). This generator is the standard one used in most simulation software. It does not need any further randomization.

Harry

Ahmet Tosun

unread,
Apr 13, 2020, 3:22:24 PM4/13/20
to Jaamsim Users Discussion Group
Harry

I want to test different series in each non-multiple run.
I want to assign a random number to the keyword "RandomSeed".
Forexample "RandomSeed = rnd ()"

Ahmet Tosun

Harry King

unread,
Apr 19, 2020, 5:07:08 PM4/19/20
to Jaamsim Users Discussion Group
Ahmet,

The 'RandomSeed' keyword does not accept an expression, and even if it did, its value is used only to initialize the random number generator when the model is started. A change in its value would have no effect until the model is re-started. This restriction is built into the algorithm used for random number generation. It really doesn't make sense to change the random seed for a generator once it has been started.

The best you could do is to have several random distribution objects with different random seeds, and choose the one to sample from next. Note that if you use the '?' operator to formulate your expression, e.g.  'this.condition ? [Distribution1].Value : [Distribution2].Value', then only the chosen distribution will be evaluated (short-circuited evaluation).

Harry

Ingeniería Paula

unread,
Jun 17, 2021, 12:50:56 PM6/17/21
to Jaamsim Users Discussion Group
Good morning, how can I generate the value for the randomseed? What function does randomseed do?
Thanks

Harry King

unread,
Jun 20, 2021, 8:20:47 PM6/20/21
to Jaamsim Users Discussion Group
Paula,

Wikipedia gives a good description. Or consult any textbook on discrete event simulation.

Harry

Arnaldo Matute

unread,
Mar 18, 2022, 2:00:02 PM3/18/22
to Jaamsim Users Discussion Group
Hi All!
I would like to generate a random integer that has to be different for every run. I used the DiscreteDistribution to do it and set a list of ten different integers with 0.1probablity each. Every time I run the simulation I get the same value. Just when I change the seed it changes but with the same seed, I get always the same value. 
Is there a way to solve this?
Regards,
Arnaldo 

Harry King

unread,
Mar 18, 2022, 2:22:09 PM3/18/22
to Jaamsim Users Discussion Group
Arnoldo,

Set the GlobalSubstreamSeed input for Simulation to this.RunNumber.  This will cause each of your distribution to give a different random sample for each simulation run.

Note that the default for this input is this.ReplicationNumber which gives a different random sample for each replication. Are you sure that you want separate runs and not just multiple replications of the same simulation?

Harry

Arnaldo Matute

unread,
Mar 20, 2022, 5:17:03 PM3/20/22
to Jaamsim Users Discussion Group
Hello Harry!
Thanks for your kind reply. However, I have not been yet successful with this.
The text object I see to confirm my random integer shows me the media of all values in the ProbabilityList. I avoid this by setting an EntityGenerator that generates just one entity and Assign the [DiscreteDistribution].Value to an attribute of this entity, which I read and see in a text object. (If there is a better way to do this, I'd appreciate your advice)
When I run the simulation from the beginning, I always get the same number either with this.ReplicationNumber or this.RunNumber.
I want a different value for each time I run the simulation from the beginning. I have not worked so far with replications but I would consider this if you consider it could help me.

Regards,
Arnaldo

Harry King

unread,
Mar 20, 2022, 7:25:53 PM3/20/22
to Jaamsim Users Discussion Group
Arnaldo,

All simulation software packages are designed to give repeatable results. It will always give you the same results every time you launch it. 

A way to get around this feature would be to set the GlobalSubstreamSeed input to this.PresentDate(7). This would set the input to the millisecond component of the time at which you start the simulation run. This will give you up to 1000 different results. You could increase the maximum number of different results to 60,000 by using the 'seconds' value and converting it to milliseconds, i.e. 'this.PresentDate(6)*1000 + this.PresentDate(7)'.

Unless you are trying to create some kind of game, I question whether this is what you should be doing. The normal procedure for simulation is to create a scenario which is then executed for 10 or more replications to give average values and uncertainties for the model outputs. An individual simulation run is not much use.

Harry

Arnaldo Matute

unread,
Mar 23, 2022, 11:18:13 AM3/23/22
to Jaamsim Users Discussion Group
Hi Harry!
Your advice solved my issue. I also understand your concern about the repeatability I am losing and will think about it.
However, my simulation stops very soon with an error message since I did this non-repeatable setting of seeds.
The log viewer shows me this:

Saving...
Runtime error in replication 1 of scenario 1 at time 5064,049612 s:
null
Thrown exception call stack:
com.jaamsim.basicsim.ErrorException.getMessage(ErrorException.java:59)
java.lang.Throwable.getLocalizedMessage(Unknown Source)
java.lang.Throwable.toString(Unknown Source)
java.lang.Throwable.<init>(Unknown Source)
java.lang.Exception.<init>(Unknown Source)
java.lang.RuntimeException.<init>(Unknown Source)
com.jaamsim.basicsim.ErrorException.<init>(ErrorException.java:51)
com.jaamsim.input.OutputHandle.getValue(OutputHandle.java:156)
com.jaamsim.input.OutputHandle.getValueAsDouble(OutputHandle.java:197)
com.jaamsim.input.ExpEvaluator$CachedResolver.resolve(ExpEvaluator.java:262)
com.jaamsim.input.ExpParser$ResolveOutput.evaluate(ExpParser.java:441)
com.jaamsim.input.ExpParser$IndexCollection.evaluate(ExpParser.java:535)
com.jaamsim.input.ExpParser$ResolveOutput.evaluate(ExpParser.java:439)
com.jaamsim.input.ExpParser$Assignment.evaluate(ExpParser.java:252)
com.jaamsim.input.ExpEvaluator.evaluateExpression(ExpEvaluator.java:397)
com.jaamsim.ProcessFlow.Assign.addEntity(Assign.java:59)
com.jaamsim.ProcessFlow.LinkedDevice.sendToNextComponent(LinkedDevice.java:134)
com.jaamsim.ProcessFlow.Server.processStep(Server.java:90)
com.jaamsim.ProcessFlow.Device.endStep(Device.java:234)
com.jaamsim.ProcessFlow.Device$EndStepTarget.process(Device.java:214)
com.jaamsim.events.EventManager.executeTarget(EventManager.java:171)
com.jaamsim.events.EventManager.execute(EventManager.java:256)
com.jaamsim.events.Process.run(Process.java:101)

 
Any suggestions?

Thank you for your kind help.
Regards,
Arnaldo

Harry King

unread,
Mar 23, 2022, 11:24:59 AM3/23/22
to Jaamsim Users Discussion Group
Please attach a copy of your model so that I can reproduce the error. It occurs when one of your Assign objects tries to evaluate an expression.

Harry

Arnaldo Matute

unread,
Mar 23, 2022, 11:35:06 AM3/23/22
to Jaamsim Users Discussion Group
Hi Harry!
I checked all my "assign" objects and found the issue. I already solved it.

Thank you that much again.

Regards,
Arnaldo 

Harry King

unread,
Mar 25, 2022, 4:02:44 PM3/25/22
to Jaamsim Users Discussion Group
Arnaldo,

I'm glad to hear that you were able to fix the model yourself. However, JaamSim should have given you a more useful error message. Could you please attach the version of your model that generated the error so that I can see what happened? I haven't been able to get this type of error myself.

Harry

Harry King

unread,
Apr 27, 2022, 12:07:48 AM4/27/22
to Jaamsim Users Discussion Group
Arnaldo,

Release 2022-03 will give a more useful error message for this condition.

Harry

Reply all
Reply to author
Forward
0 new messages