Last updated on 16th July 2024
The Simudyne SDK uses a defined seed value as the input to it's Programmable Random Number Generator (PRNG). This value is set most commonly via the simudyneSDK.properties file. However there are other conditions where you are able to change this that you should be aware of / make usage of accordingly. For batch runs the core seed is used to generate the individual seeds for each run.
core.prng-seed = 1640702558671097951
in your simudyneSDK.properties file."seeds": [1234, 2314, 4213]
please refer to the REST API for more.this.getContext().getPrng().generator.getSeed()
this.getContext().getPrng().generator.setSeed(12345)
however take note that certain parts of setup or initialization may have already run, and depending on when you set this value it may not be affected by your actions.During the run you are able to get the seed by running this.getConfig().getInt("simudyne.core.prng-seed")
. Note that because you are in the code there is the additional simudyne.
before core.prng-seed
this is default behavior for any configuration to allow for external providers to have custom configuration.
Given the ability to get the seed you could write your own random number generator using the seed value from the config in order to work with random numbers. However given that said generators could exist in different states, the ability to run actions in parallel, and agent message passing the chance for the randomness provided to create a non-deterministic model is prevelant.
Our suggestion is to make usage of the SDK's prng which can be acessessed via the follow methods.
If you require the usage of a Random
for usage in random number generation you can call getRandom
from the prng
to return a Random
generator set to the seed of your simulation.
public class myModel extends AgentBasedModel<GlobalState> {
public void setup() {
SeededRandom pnrg = this.getContext().getPRNG();
pnrg.generator.nextDouble();
}
...
}
public class myAgent extends Agent<myModel.Globals> {
public double funcRandom() {
return this.getPrng().generator.nextDouble();
}
public static Action<myAgent> sendRandom = new Action<>(myAgent.class,
agent -> {
agent.send(Message.Double.class, msg -> { msg.setBody(agent.getPrng().generator.nextDouble());});
});
}
By accessing the PRNG you are able to also get various distributions and a sample set of values to use within your model. The following distributions are available.