> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eucaengine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Determinism & replay

> One canonical seeded RNG drives the whole engine, so the same seed and inputs reproduce the same run — byte for byte.

Euca is **deterministic by construction**. The **simulation** runs on a single canonical
seeded RNG — no ambient `rand`, no wall-clock in the tick, no per-system randomness: every
stochastic decision in a tick draws from that one stream (a CI test enforces it — no hidden
RNG). Give the engine the same seed and the same inputs and you get the same run back, every
time, within a given build and platform.

```mermaid theme={null}
flowchart LR
    subgraph a ["Run A"]
        direction LR
        S1["seed + inputs"] --> T1["ticks"] --> D1["digest 0xAB…"]
    end
    subgraph b ["Run B — replay"]
        direction LR
        S2["same seed + inputs"] --> T2["ticks"] --> D2["digest 0xAB…"]
    end
    D1 <-.->|"identical, byte for byte"| D2
```

<Note>
  One RNG, engine-wide. The engine knows the dice — so a run is a pure function of
  `(initial state, seed, inputs)`.
</Note>

## Why it matters

Determinism is the property the rest of the engine is built on:

<CardGroup cols={2}>
  <Card title="Replay" icon="rotate-left">
    Re-run the same world from the same seed and inputs to reproduce a result exactly —
    no flakiness, no "works on my machine."
  </Card>

  <Card title="Forks that mean something" icon="code-branch">
    A [fork](/concepts/forks) only isolates a counterfactual if the fork and the original
    would otherwise evolve identically. Determinism is what makes the comparison valid.
  </Card>

  <Card title="A real answer key" icon="key">
    Because the next step is a fixed distribution rather than noise, Euca can report it
    exactly — the basis of [world-model evaluation](/evaluation/overview).
  </Card>

  <Card title="Reproducible datasets" icon="database">
    Trajectories recorded from the engine carry a content digest, so a dataset can be
    verified bit-for-bit against the run that produced it.
  </Card>
</CardGroup>

## How reproducibility is checked

The engine can flatten the entire world into a canonical, ordered representation — entities
sorted by id, components sorted by name, fields in declaration order — and hash it into a
stable digest. Two runs that diverge by a single field produce different digests, which is
how the engine's own test suite and the evaluation track verify that a replay is exact.

Physics is part of this guarantee: the solver is bit-deterministic, so contacts and
integration reproduce exactly across runs on the same platform.

<Info>
  Determinism is guaranteed for a given build and platform. The digest is a within-platform
  reproducibility oracle, not a claim of identical floating-point results across different
  CPU architectures.
</Info>

## Replaying through the API

State is data, so a run can be captured and restored as data. Two complementary tools:

* **Snapshots** capture a labeled summary of the world at a tick, and `GET /snapshot/diff`
  compares two of them — see [Forks & counterfactuals](/concepts/forks).
* **Scenarios** serialize the whole world — entities, templates, rules, and assertions —
  as a declarative document. `GET /scenario` exports the current world and `POST /scenario`
  rebuilds it. A scenario plus a seed is a reproducible starting point you can save, edit,
  and re-apply.

```bash theme={null}
# Export the current world as a declarative scenario document.
curl -s http://localhost:3917/scenario > world.json

# Later — or on another machine — rebuild that exact world and continue.
curl -s -X POST http://localhost:3917/scenario \
  -H 'content-type: application/json' --data @world.json
```
