Skip to Content

Seed

Deterministic RNG for the run: a single seed int on Ephemeral is advanced after each draw (System.Random + feedback into store).

State (Ephemeral)

KeySemantics
seedInt; 0 means “auto-generate” on first GetSeed() (uses TickCount xor Guid hash)

How it looks in save / template JSON

In the Gnosis Engine’s default template (Assets/Resources/Data/ephemeral.json), run data lives under Ephemeral. For this service you only need to think about one field — at path Ephemeral.seed:

ephemeral.json
{ "seed": 0 }

(That object is the Ephemeral JSON object: the file wraps it as "Ephemeral": { ... }; the snippet above is just the Seed-owned part.)

  • 0 — “pick a fresh run seed” on first real GetSeed() in play.
  • After RNG calls, seed becomes a non-zero integer until something resets it.

Events

None.

Functions

FunctionParametersResult
GetSeed{ seed }
RangeIntmin, max{ value } in [min, max)
RangeFloatmin, max{ value } in [min, max]
RandomFloat01{ value } in [0,1)
RandomInt32{ value } non-negative int

Usage examples (real call sites)

GetSeed — stable basis for a run

Game code often reads GetSeed once (or when the run starts) so deterministic choices—encounter rotation, loot tables, procedural steps—stay stable for that run. Example pattern:

SeedService.Example1.cs
private int TryReadSeedFromSeedService() { if (Context?.Store == null || Context.CallService == null) return 0; var empty = GnosisNode.CreateObject(Context.Store); var result = CallService("Seed", "GetSeed", empty); if (!result.Success || !result.Data.IsValid || result.Data.Type != GnosisValueType.Object) return 0; var n = result.Data["seed"]; if (!n.IsValid) return 0; if (n.Type == GnosisValueType.Int) return (int)n; if (n.Type == GnosisValueType.Long) return (int)(long)n; return 0; }

(Excerpt from lines 44–62 in a sample game project; any service with CallService can do the same.)

RangeInt — pick index for currency SFX

GnosisCurrencyService asks Seed for an index in [0, count) when choosing which configured clip to play from a currency row’s increaseSfx / decreaseSfx list (see GetSeededRandomIndex in the engine package):

SeedService.Example2.cs
private int GetSeededRandomIndex(int count) { if (count <= 1 || Context?.Store == null || Context.CallService == null) return 0; var args = GnosisNode.CreateObject(Context.Store); args.Set("min", 0); args.Set("max", count); var result = CallService("Seed", "RangeInt", args); if (!result.Success || !result.Data.IsValid || result.Data.Type != GnosisValueType.Object) return 0; var valueNode = result.Data["value"]; // ... normalizes int / long / float into index ... return value; }

JSON invocation (from rules / data)

Same calls are often expressed as invocations with service / function / parameters. Example for a random roll:

invocation.json
{ "service": "Seed", "function": "RangeInt", "parameters": { "min": 0, "max": 10 } }

(Return value is in the function result’s Data object, e.g. value, same as C#.)

Statistics

None.

Last updated on