All documents

Determinism and Reproducibility

spicegrinder-icon

© 2026 Obsvra. This document describes SpiceGrinder and is provided to help you evaluate and use it. It is not a license to reproduce, adapt, or use this material to build a competing product or service. Full terms: the SpiceGrinder EULA.

SpiceGrinder makes three different promises about getting the same results again. They are worth keeping apart, because only the first two mean “the same bytes”.

  1. Exact replay
  2. Cross-platform replay
  3. Statistical reproducibility

The page then covers random streams (how each node gets its values, and how to reproduce a stream yourself), upgrading Java, and what changes the output.

1. Exact replay

Run the same model with the same seed on the same SpiceGrinder version and a supported runtime, and you get byte-identical output.

Set the seed in the model (<dataset seed="42">) or on the command line (grind --seed 42 model.xml). If you didn’t set one, SpiceGrinder picked one and logged it: Grind prints it to stderr (unless --quiet), and the run summary records it when --audit or --performance is on. Pass that value back with --seed to replay the run. The order in which --seed, --no-seed and the model’s own seed apply is in Grind.

“The same model” means everything the model reads:

  • the model file and every model it imports;
  • data files read by FlatFile, and tables read by Database;
  • your formatting configuration (~/.spicegrinder/formats.properties), which controls things like address layouts;
  • the same options: --count, --node.

Exact replay doesn’t cover ServiceCall (its values come from another service), or custom components and custom random generators that are themselves non-deterministic.

2. Cross-platform replay

Exact replay also holds across operating systems and processors. A model and seed produce the same bytes on macOS, Windows and Linux, on Intel/AMD (x86-64) and ARM (Apple Silicon, Linux arm64), when run on the same Java feature release. Every release is checked against a set of reference outputs on each supported platform before it ships.

This works because:

  • SpiceGrinder’s default random generator is plain integer arithmetic, which behaves identically everywhere.
  • Java’s floating-point arithmetic follows IEEE 754 strictly on every platform.
  • Every exponential, logarithm, power and trigonometric function SpiceGrinder uses to shape distributions goes through Java’s StrictMath. Its results are defined bit for bit, rather than through faster CPU-specific versions that can differ in the last digit.
  • Numbers are printed with Java’s exactly specified shortest representation.

Supported runtime:

Supported
JavaJava 25, any 25.0.x update (bundled with the installers; required for the plain jar)
Operating systemsmacOS, Windows, Linux
Processorsx86-64 and arm64

An update within Java 25.0.x is expected to give the same output. The reference outputs are checked again whenever the Java runtime bundled with the installers changes.

Windows on ARM is expected to give the same output but isn’t covered by the release check yet. There is no native Windows ARM package: you run the Windows x64 installer under Windows’ x64 emulation, or run the jar on a native arm64 Java 25.

3. Statistical reproducibility

On any runtime and any 1.x version, a model produces values from the same distributions: the same means, percentiles, correlations and rates, within sampling error. Individual values may differ.

This is the guarantee to rely on when you upgrade Java, change your model, or compare results from different versions. It is not determinism: two runs agree about the shape of the data, not about each value.

Random streams

Every node that draws random values has its own random stream, derived from the dataset’s seed and the node’s name. This is the default in 1.0 and is set by the streams attribute on <dataset>:

streamsMeaning
per-node (default)One stream per node, derived from the seed and the node’s name, as described below
sharedAll nodes share one stream, in the order values are pulled. This is the stream layout of the SpiceGrinder Beta releases
anything elseA load error that lists the valid values
<dataset seed="42" streams="shared">

What per-node streams give you

With the same seed:

  • Adding, removing or reordering nodes doesn’t change what any other node draws.
  • Two runs that differ in one node’s parameters differ only where that node’s values flow. That makes same-seed scenario comparisons meaningful.
  • A node that draws a variable number of values (Truncate in truncate mode, Poisson in standard mode, and any Normal) shifts only its own stream.

What they don’t give you

  • A node’s own later values still move when its own draw count changes, for example with new Truncate bounds.
  • Values are drawn in the order the node is pulled, not by row. When a Mix or Switch picks a branch, that branch’s next value goes to the current row. Changing the Mix weights, or the key a Switch uses, changes which rows pick a branch, and so which values those rows see.
  • A stream follows the node’s name. Renaming a node gives it a new stream, as if it were a new node, and only that node’s values change. The same applies to anything that changes the name path: renaming an <Import>, or adding or changing its prefix. Treat renaming a node as a model change, like changing its parameters.

Node names

A node’s identity is its final, fully prefixed name, the same name ModelNormalizerApp reports and writes when it flattens a model:

  • A node in the top-level model uses its name, for example Design.
  • A node inside an <Import> uses the import’s prefix, a dot, then the node’s name within the imported file, at every level. A node X in leaf.xml, imported with prefix="b" by mid.xml, which the top-level model imports with prefix="a", is a.b.X.
  • The prefix is the Import’s prefix, else its name, else the literal import.
  • The name is compared as exact text, encoded as UTF-8, with no case folding or Unicode normalization.

So the stream doesn’t depend on the order of <nodes>, a model and its flattened form give the same output, and importing one file twice under two prefixes gives two different streams. The XML, JSON and compact formats give the same identities.

How a stream is derived

The derivation is part of what 1.0 promises, so you can reproduce a node’s stream from the logged seed and the node’s name.

nodeSeed = first 8 bytes, read as a big-endian signed 64-bit integer, of
           SHA-256( UTF-8("spicegrinder-substream-v1") || 0x00
                    || rootSeed as 8 bytes, big-endian
                    || UTF-8(node name) )
stream   = new Random(nodeSeed)

new Random(nodeSeed) is SpiceGrinder’s default generator (com.obsvra.spicegrinder.core.defaults.Random), which wraps Java’s L64X128MixRandom. rootSeed is the seed that applies to the run: the one in the log. nodeSeed can be any long, including zero and negative values. The version tag, spicegrinder-substream-v1, means a future change to the algorithm would use a new tag and not silently change what this one produces.

Known answers, to check an implementation of the derivation:

Root seedNode namenodeSeedFirst nextDouble()
42A84237557893870079200.2321609144243203
42lib.HeartRate81098152011461944410.08926064215314922

Seeds, custom generators and code

  • Seed 0 and negative seeds. A seed of 0 means no seed, wherever it comes from (--seed 0, a request’s seed, <dataset seed="0">) and in either streams layout: SpiceGrinder draws its own, and Grind and the Service log the seed it drew, so you can replay that run by passing the logged number. A negative seed is an error.

  • No seed. If the model has no seed and none is given, SpiceGrinder draws one fresh root seed and derives from it. Streams are independent of each other, and the run isn’t reproducible. Grind always resolves a seed, so a Grind run can always be replayed from its log.

  • A custom random class (Pro, <dataset random="com.example.MyRNG">). With per-node, SpiceGrinder constructs one instance of your class for each node that draws values, using its (long seed) constructor with that node’s nodeSeed. The constructor may receive any long, including negative values. A class without a (long seed) constructor can’t be given separate streams: loading the model fails with an error that names the fix, streams="shared". With shared, the class is constructed once, as before.

  • Java code. An IRandom installed from code with Randoms.set(IRandom) is used by every node of a load that has no seed of its own, whatever streams says. A load that has a seed replaces the override with its own streams, and the override stays replaced for the rest of the process. A seed counts if it comes from the command line, a request’s seed, the model’s <dataset seed="..."> or ModelLoader.loadDocumentWithSeed; a seed of 0 means no seed, so it leaves the override in force. Every Grind, Service, MCP and Lambda run supplies a seed, so none of them uses the override. The reason is replay: a stale override left over from earlier code must not be able to stop a seeded run from reproducing. To have your own generator in a seeded run, name it in the model with <dataset random="..."> (Pro). To have it in a test, load a model that has no seed:

    Randoms.set(new MyRandom());                        // before loading, and set it again after any seeded load
    IGenerator g = new ModelLoader().load("model.xml"); // no seed in the model: every node draws from MyRandom
  • Library models loaded by the Java Import class. The Import generator, when you build a graph from Java code (Pro direct construction), names its library’s nodes’ streams under the Import node’s own name, exactly as <Import name="lib"/> does in a model file: U in the library draws as lib.U. Two Java Imports of the same library, with different names, under the same seed draw different values. The seed is the process’s current seed; the library’s own <dataset seed> is applied (to the process) only when the process has no seed yet, so a library with a fixed seed stays reproducible when it is the first thing loaded. Before BUG-12 was fixed this class loaded its library through its own loader and left the prefix out (BUG-12), so two imports of one library drew identical values; values from graphs built that way differ from before.

Per-entity streams (ProcessFlow streams="per-entity")

With per-node streams, a ProcessFlow input hands its nth value to whichever entity draws nth. In a what-if that changes one routing probability, some entities take a different path, the order of draws at every later station changes, and nearly every entity downstream gets different values: the difference between the two runs is mostly reshuffling, not the change being studied. streams="per-entity" on the ProcessFlow node removes that. The value an entity gets depends only on the seed, the input node, the entity, the role and how many times this entity has drawn for that role before, so a what-if changes an entity’s draws only where the change reaches it (common random numbers).

  • What is keyed. Service times (role service.<Station>, counted per station), patience (patience.<Station>), the entity’s attributes (role entity, once), and every routing choice (route.<Station>, counted per station; the entry choice is route.entry). The arrival gaps are not: they belong to no entity and stay one stream. Breakdowns, restocks and fleet and tie choices stay per-node.

  • The entity id is its arrival number (1, 2, …). A what-if that changes the arrivals renumbers the entities after the first change; to keep common random numbers across such changes, give the arrivals as a fixed population (arrivalAt from a file).

  • The derivation (versioned by the tag spicegrinder-entitystream-v1), with mix the SplitMix64 step (the finalizer of z + 0x9E3779B97F4A7C15: z = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9; z = (z ^ (z >>> 27)) * 0x94D049BB133111EB; z ^ (z >>> 31)):

    roleKey  = first 8 bytes, big-endian, of SHA-256( UTF-8("spicegrinder-entitystream-v1") || 0x00 || UTF-8(role) )
    drawSeed = mix(mix(mix(mix(inputNodeSeed) ^ entity) ^ roleKey) ^ k)

    inputNodeSeed is the input node’s per-node seed (above) and k the entity’s count of earlier draws for that role (0 for the first). Before the draw, every random node in the input’s subtree (the input itself, and the nodes it reads, such as the two Uniforms of a Calculate) restarts its stream as a fresh L64X128MixRandom seeded with mix(drawSeed ^ nodeSeed), its own per-node seed. A routing uniform is the first uniform of a stream seeded with the drawSeed of the ProcessFlow’s own per-node seed and role route.<Station>. Known-answer vectors: mix(0) = 0xe220a8397b1dcdaf; roleKey("service.A") = 0x653c38a4e03d2cae; drawSeed(123456789, 42, roleKey("service.A"), 3) = 0x31e8dbb9579d3c18.

  • Limits. Nodes with state across rows (Markov, Recur, Sequence, a FlatFile read in order) keep one state shared by all entities: only their randomness is reseeded. A shared queue or pool still couples entities, so a what-if that changes waits changes later times; that is the model, not stream noise. Per-entity streams need the per-node layout and the built-in generator: with <dataset streams="shared"> or a custom dataset.random the run stops with an error. Restarting a stream per draw costs a little time per draw.

  • Default. streams="auto": per-entity for a ProcessFlow that uses guards, clock or an expression routing condition (the D33 stateful-entity features), per-node for every other. Under auto a node whose inputs cannot be keyed (<dataset streams="shared">, a custom dataset.random) quietly keeps per-node, decided before its first keyed draw so a run is never a mix; an explicit streams="per-entity" is an error there. Models written before D33 use none of these features, so their output is unchanged.

Reproducing output from a Beta release

Add streams="shared" to <dataset> to draw from one shared stream in pull order, as the Beta releases did. Models written for a Beta release don’t have the attribute, so with 1.0 they use per-node and produce different values from the same distributions.

Upgrading Java

The default random generator is supplied by Java. Java promises that it repeats a sequence only within one version, so moving to a different Java feature release (for example from 25 to 26) may change your output. Statistical reproducibility still holds.

SpiceGrinder Pro can pin the generator. Ship your own IRandom class with the model and name it with <dataset random="com.example.MyRNG"> (see Random number generator override). Everything else SpiceGrinder computes is defined independently of the Java version, so a pinned generator gives exact replay across Java versions as well. Your class should use only algorithms it fully defines itself, or ones Java specifies exactly, such as java.util.Random. A class that wraps RandomGenerator.of(...), or calls nextGaussian() from the newer random-generator API, inherits the same Java-version caveat as the default.

What changes the output

ChangeSame bytes?
Run again, same seed, same machineYes
Same seed, a different supported OS or processorYes
Same seed, a different Java 25 updateYes (re-verified when the bundled Java changes)
Same seed, a different Java feature releaseNot guaranteed; same distributions. Yes with a pinned IRandom (Pro).
Same seed, a different SpiceGrinder 1.x versionYes, unless the release notes name a changed component
Adding, removing or reordering a node, with per-node streams (the default)Other nodes keep their values. The node you add or remove changes the output’s columns
Adding, removing or reordering a node, with streams="shared"No: later draws shift. Same distributions
Renaming a node, or an <Import>’s name or prefix, with per-node streamsThe renamed nodes get new values; other nodes are unchanged
Same library through <Import name="X"> in a model file and through the Java Import class named X, under one process seedYes: both name the library’s nodes X.NodeName
Changing the streams attributeNo: different values, same distributions
No seedNo: a new seed each run (logged, so you can replay it)