@patterkit/runtime 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -678,7 +678,13 @@ declare class Flow {
678
678
  private conditionAst;
679
679
  /** Record an entry of a node (entered-only; spec §7): bumps the flow + world counts. */
680
680
  private enter;
681
- /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32. */
681
+ /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32.
682
+ *
683
+ * The mixing is @wildwinter/expr's makePrng, not a copy inline here. It is a
684
+ * fixed published algorithm that both product families need and neither
685
+ * owns, and it existed thirteen times across the two of them. `rngState` is
686
+ * still the serialisable position, so saves are unaffected: a generator is
687
+ * made from it, drawn once, and the new state written back. */
682
688
  private readonly rng;
683
689
  private beatResult;
684
690
  /**
package/dist/index.d.ts CHANGED
@@ -678,7 +678,13 @@ declare class Flow {
678
678
  private conditionAst;
679
679
  /** Record an entry of a node (entered-only; spec §7): bumps the flow + world counts. */
680
680
  private enter;
681
- /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32. */
681
+ /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32.
682
+ *
683
+ * The mixing is @wildwinter/expr's makePrng, not a copy inline here. It is a
684
+ * fixed published algorithm that both product families need and neither
685
+ * owns, and it existed thirteen times across the two of them. `rngState` is
686
+ * still the serialisable position, so saves are unaffected: a generator is
687
+ * made from it, drawn once, and the new state written back. */
682
688
  private readonly rng;
683
689
  private beatResult;
684
690
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/engine.ts
2
- import { evaluate, deserialiseAst } from "@wildwinter/expr";
2
+ import { evaluate, deserialiseAst, makePrng, toUint32 } from "@wildwinter/expr";
3
3
  import { matchedSpecificity as scoreSpecificity } from "@wildwinter/expr-specificity";
4
4
  import { ScopeRegistry } from "@wildwinter/scoperegistry";
5
5
  import { patterDialect, interpolate, splitRef, stripCaptions } from "@patterkit/dialect";
@@ -615,7 +615,7 @@ var Flow = class {
615
615
  constructor(id, host, seed) {
616
616
  this.id = id;
617
617
  this.host = host;
618
- this.rngState = seed >>> 0;
618
+ this.rngState = toUint32(seed);
619
619
  this.local = this.freshLocal();
620
620
  const scopes = { ...host.shared.toEvalContext().scopes };
621
621
  scopes["patter"] = this.patterResolver;
@@ -913,7 +913,7 @@ var Flow = class {
913
913
  }
914
914
  /** @internal Restore this flow from a snapshot. */
915
915
  restore(snap) {
916
- this.rngState = snap.rngState >>> 0;
916
+ this.rngState = toUint32(snap.rngState);
917
917
  this.visitCounts = new Map(Object.entries(snap.visits ?? {}));
918
918
  const c = snap.cursor;
919
919
  this.started = true;
@@ -1228,14 +1228,19 @@ var Flow = class {
1228
1228
  this.visitCounts.set(id, (this.visitCounts.get(id) ?? 0) + 1);
1229
1229
  this.host.sharedVisits.set(id, (this.host.sharedVisits.get(id) ?? 0) + 1);
1230
1230
  }
1231
- /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32. */
1231
+ /** Next float in [0, 1): the shared custom PRNG, or this flow's serialisable mulberry32.
1232
+ *
1233
+ * The mixing is @wildwinter/expr's makePrng, not a copy inline here. It is a
1234
+ * fixed published algorithm that both product families need and neither
1235
+ * owns, and it existed thirteen times across the two of them. `rngState` is
1236
+ * still the serialisable position, so saves are unaffected: a generator is
1237
+ * made from it, drawn once, and the new state written back. */
1232
1238
  rng = () => {
1233
1239
  if (this.host.customRng) return this.host.customRng();
1234
- const a = this.rngState + 1831565813 | 0;
1235
- this.rngState = a;
1236
- let t = Math.imul(a ^ a >>> 15, 1 | a);
1237
- t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
1238
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
1240
+ const prng = makePrng(this.rngState);
1241
+ const draw = prng.next();
1242
+ this.rngState = prng.state();
1243
+ return draw;
1239
1244
  };
1240
1245
  // -- Strings / beats ------------------------------------------------------
1241
1246
  beatResult(beat) {