@sdxc/random 0.0.0-pre.1 → 2026.10.6

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.
Files changed (2) hide show
  1. package/README.md +25 -13
  2. package/package.json +11 -2
package/README.md CHANGED
@@ -115,22 +115,30 @@ A `Random` with `seed`, `derive(label)` and `state()`.
115
115
 
116
116
  ## Pattern: A Reproducible Fuzz Run
117
117
 
118
- Draw a fresh seed per run unless one is supplied, and print it, so a failing run replays from that number.
118
+ Draw a fresh seed per run unless one is supplied, and name the suite after it, so a failure reports the number that replays it.
119
119
 
120
120
  ```typescript
121
121
  import { createRandom, systemSeed } from "@sdxc/random";
122
-
123
- let seed = Number(process.env.FUZZ_SEED) || systemSeed();
124
- console.info(`fuzz seed: ${seed}`);
125
-
126
- let random = createRandom(seed);
127
- let cases = Array.from({ length: 1000 }, () => ({
128
- minute: random.int(0, 59),
129
- hour: random.int(0, 23),
130
- weekday: random.pick(["MON", "TUE", "WED", "THU", "FRI"]),
131
- }));
122
+ import { describe, expect, test } from "vitest";
123
+
124
+ const SEED = Number(process.env.FUZZ_SEED) || systemSeed();
125
+
126
+ describe(`cron parsing (FUZZ_SEED=${SEED})`, () => {
127
+ test("every generated expression parses", () => {
128
+ let random = createRandom(SEED);
129
+
130
+ for (let index = 0; index < 1000; index++) {
131
+ let minute = random.int(0, 59);
132
+ let hour = random.int(0, 23);
133
+ let weekday = random.pick(["MON", "TUE", "WED", "THU", "FRI"]);
134
+ expect(parseCron(`${minute} ${hour} * * ${weekday}`).success).toBe(true);
135
+ }
136
+ });
137
+ });
132
138
  ```
133
139
 
140
+ `parseCron` is the function under test.
141
+
134
142
  ## Pattern: Persisting A Simulation
135
143
 
136
144
  Store each stream's state next to the world it shaped, and validate it on load, since a save file is untrusted input.
@@ -150,14 +158,18 @@ function save(): string {
150
158
  return JSON.stringify({ turn, random: random.state() });
151
159
  }
152
160
 
153
- function load(text: string) {
161
+ function load(text: string): boolean {
154
162
  let parsed = s.parseSafe(SAVE_SCHEMA, JSON.parse(text));
155
- if (!parsed.success) throw new Error("Corrupt save file");
163
+ if (!parsed.success) return false;
164
+
156
165
  turn = parsed.value.turn;
157
166
  random = restoreRandom(parsed.value.random);
167
+ return true;
158
168
  }
159
169
  ```
160
170
 
171
+ A save that fails the schema leaves the running game as it was, and `load` answers `false` so the caller can say the file was unreadable.
172
+
161
173
  ## Versioning
162
174
 
163
175
  Releases are dated rather than semantic. A version is the UTC date it was published, written `YYYY.M.D`, so `2026.9.4` is the release from 4 September 2026. At most one release goes out per day.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/random",
3
- "version": "0.0.0-pre.1",
3
+ "version": "2026.10.6",
4
4
  "description": "Seeded and system random streams with integer, float, pick and shuffle draws, and resumable state",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "optional": true
17
17
  }
18
18
  },
19
- "gitHead": "47e70835fe3943a13cf37f07c3dfb8203aba1c35",
19
+ "gitHead": "b1067eb20fc47ec51ff8c4de47d07dc3f9c00466",
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },
@@ -24,5 +24,14 @@
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/sergiodxa/monorepo.git",
26
26
  "directory": "packages/random"
27
+ },
28
+ "homepage": "https://sdxc.sergiodxa.com/api/random",
29
+ "author": {
30
+ "name": "Sergio Xalambrí",
31
+ "url": "https://sergiodxa.com"
32
+ },
33
+ "funding": {
34
+ "type": "github",
35
+ "url": "https://github.com/sponsors/sergiodxa"
27
36
  }
28
37
  }