{"data":{"markdownRemark":{"html":"<h2 id=\"beginning-with-the-seed\"><a href=\"#beginning-with-the-seed\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Beginning with the Seed</h2>\n<p>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.</p>\n<ul>\n<li>Setting <code class=\"language-text\">core.prng-seed = 1640702558671097951</code> in your simudyneSDK.properties file.</li>\n<li>In the Scenario or Model Sampler REST API you are able to set seeds for the different runs by modifying <code class=\"language-text\">&quot;seeds&quot;: [1234, 2314, 4213]</code> please refer to the <a href=\":version/rest_api/rest_api\">REST API</a> for more.</li>\n<li>If using the BatchDefinitionsBuilder you can provide a .forGeneratorSeed(467854386543L) as part of the .create() build or within the .createScenario section of the ScenarioDefinitionsBuilder</li>\n<li>If using the ModelSamplerDefinitionsBuilder.forSeeds(123,345,678) can be used.</li>\n<li>You can get the existing seed by calling <code class=\"language-text\">this.getContext().getPrng().generator.getSeed()</code> </li>\n<li>Finally within a run you may manually set the seed via <code class=\"language-text\">this.getContext().getPrng().generator.setSeed(12345)</code> 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.</li>\n</ul>\n<p>During the run you are able to get the seed by running <code class=\"language-text\">this.getConfig().getInt(&quot;simudyne.core.prng-seed&quot;)</code>. Note that because you are in the code there is the additional <code class=\"language-text\">simudyne.</code> before <code class=\"language-text\">core.prng-seed</code> this is default behavior for any configuration to allow for external providers to have custom configuration.</p>\n<h2 id=\"example-usages\"><a href=\"#example-usages\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example Usages</h2>\n<p>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. </p>\n<p>Our suggestion is to make usage of the SDK's prng which can be acessessed via the follow methods.</p>\n<p>If you require the usage of a <code class=\"language-text\">Random</code> for usage in random number generation you can call <code class=\"language-text\">getRandom</code> from the <code class=\"language-text\">prng</code> to return a <code class=\"language-text\">Random</code> generator set to the seed of your simulation.</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">myModel</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">AgentBasedModel</span><span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>GlobalState<span class=\"token punctuation\">></span></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        SeededRandom pnrg <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getContext</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPRNG</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        pnrg<span class=\"token punctuation\">.</span>generator<span class=\"token punctuation\">.</span><span class=\"token function\">nextDouble</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">myAgent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Agent</span><span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>myModel<span class=\"token punctuation\">.</span>Globals<span class=\"token punctuation\">></span></span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> <span class=\"token function\">funcRandom</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t\t<span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPrng</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>generator<span class=\"token punctuation\">.</span><span class=\"token function\">nextDouble</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\t<span class=\"token punctuation\">}</span>\n\n\t<span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> Action<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>myAgent<span class=\"token punctuation\">></span></span> sendRandom <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Action</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>myAgent<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span>\n\t\tagent <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n\t\t  agent<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Message<span class=\"token punctuation\">.</span>Double<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> msg <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span> msg<span class=\"token punctuation\">.</span><span class=\"token function\">setBody</span><span class=\"token punctuation\">(</span>agent<span class=\"token punctuation\">.</span><span class=\"token function\">getPrng</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>generator<span class=\"token punctuation\">.</span><span class=\"token function\">nextDouble</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\t\t<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"available-distributions\"><a href=\"#available-distributions\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Available Distributions</h2>\n<p>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.</p>\n<ul>\n<li>BetaDistribution</li>\n<li>BinomialDistribution</li>\n<li>CauchyDistribution</li>\n<li>ChiSquaredDistribution</li>\n<li>UniformIntegerDistribution</li>\n<li>EmpiricalDistribution</li>\n<li>EnumeratedIntegerDistribution</li>\n<li>EnumeratedRealDistribution</li>\n<li>ExponentialDistribution</li>\n<li>FDistribution</li>\n<li>GammaDistribution</li>\n<li>GeometricDistribution</li>\n<li>NormalDistribution/GaussianDistribution</li>\n<li>HypergeometricDistribution</li>\n<li>LevyDistribution</li>\n<li>LogNormalDistribution</li>\n<li>MixtureMultivariateNormalDistribution</li>\n<li>PascalDistribution</li>\n<li>ParetoDistribution</li>\n<li>PoissonDistribution</li>\n<li>TDistribution</li>\n<li>TriangularDistribution</li>\n<li>UniformRealDistribution</li>\n<li>WeibullDistribution</li>\n<li>ZipfDistribution</li>\n</ul>","headings":[{"value":"Beginning with the Seed","depth":2},{"value":"Example Usages","depth":2},{"value":"Available Distributions","depth":2}],"frontmatter":{"title":"Randomness & Distributions","toc":true,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.4/docs/practices/randomness.md","versioned":true,"version":"2.4","kind":"docs","pagePath":"/practices/randomness","chronology":{"prev":{"name":"Repeatable Models","path":"/practices/repeatable-models"},"next":{"name":"FAQ","path":"/faq"}},"lastUpdated":"2026-04-21T13:56:54.847Z"}}