Skip to content

engine: RANDOM NORMAL and other random functions are not implemented #560

Open

Description

@bpowers

The engine has no random-number functions.
The MDL importer rewrites Vensim's RANDOM NORMAL, RANDOM UNIFORM and RANDOM 0 1 to NORMAL(...) and UNIFORM(...), but the compiler does not know those names, so the model fails to compile with UnknownBuiltin.
Models that add noise should simulate.

Example

noise = RANDOM NORMAL(-6, 6, 0, 1, 0)

imports as NORMAL(0, 1, 0, -6, 6) (mean, sd, seed, min, max) and is refused with UnknownBuiltin.

Why it matters

Common in real models.
Among the metasd models: pink-noise/PinkNoise2010.mdl, bathtub-statistics/integration3.mdl, critical-slowing/critical-slowing.mdl, early-warnings-catastrophe/catastropeWarning2.mdl (all through the pink_noise macro), and beer-game/RealBeer4-Sterman13.mdl; also scirev7/8.mdl, IDch15d.mdl and samples/Query_file.
Nothing simulates silently wrong today; these models just cannot run.

Fix

Add NORMAL and UNIFORM as builtins (XMILE 1.0 section 3.5.2 defines NORMAL(mean, sd[, seed]), RANDOM(min, max[, seed]), EXPRND, LOGNORMAL, POISSON), with the truncation bounds the importer already passes.
The VM and the wasm backend need a seedable, deterministic generator so a run is reproducible; the seeding rules (per run, per call's seed argument, default) have to be decided and written down.
Vensim's stream will not match bit for bit, so test by distribution: test/test-models/random/ has 500,000 Vensim samples per function plus the expected moments.
Any other RANDOM * function the importer sees (POISSON, EXPONENTIAL, ...) should get a clear "not supported" error rather than UnknownBuiltin until it is implemented.

Pointers

  • src/simlin-engine/src/mdl/xmile_compat.rs: the random normal / random 0 1 / random uniform rewrites
  • src/simlin-engine/src/builtins.rs (BuiltinFn), vm.rs, wasmgen/
  • test/test-models/random/README.md

Activity

  1. added
    engine
    on May 15, 2026
  2. changed the title [-]engine: stochastic builtins (RANDOM NORMAL / NORMAL / UNIFORM / etc.) are recognized but unimplemented -- UnknownBuiltin at simulation, blocks ~5 metasd corpus models[/-] [+]engine: RANDOM NORMAL and other random functions are not implemented[/+] on Oct 12, 2026
  3. added
    compat
    enhancement
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatengineenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions