Randomness & Distributions

Last updated on 6th May 2024

Beginning with the Seed

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.

  • Setting core.prng-seed = 1640702558671097951 in your simudyneSDK.properties file.
  • In the Scenario or Model Sampler REST API you are able to set seeds for the different runs by modifying "seeds": [1234, 2314, 4213] please refer to the REST API for more.
  • If using the BatchDefinitionsBuilder you can provide a .forGeneratorSeed(467854386543L) as part of the .create() build or within the .createScenario section of the ScenarioDefinitionsBuilder
  • If using the ModelSamplerDefinitionsBuilder.forSeeds(123,345,678) can be used.
  • You can get the existing seed by calling this.getContext().getPrng().generator.getSeed()
  • Finally within a run you may manually set the seed via 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.

Example Usages

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());});
		});
}

Available Distributions

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.

  • BetaDistribution
  • BinomialDistribution
  • CauchyDistribution
  • ChiSquaredDistribution
  • UniformIntegerDistribution
  • EmpiricalDistribution
  • EnumeratedIntegerDistribution
  • EnumeratedRealDistribution
  • ExponentialDistribution
  • FDistribution
  • GammaDistribution
  • GeometricDistribution
  • NormalDistribution/GaussianDistribution
  • HypergeometricDistribution
  • LevyDistribution
  • LogNormalDistribution
  • MixtureMultivariateNormalDistribution
  • PascalDistribution
  • ParetoDistribution
  • PoissonDistribution
  • TDistribution
  • TriangularDistribution
  • UniformRealDistribution
  • WeibullDistribution
  • ZipfDistribution