Skip to content

Commit 0d7843e

Browse files
committed
DELTA: enhance random seed utility
1 parent 2e39164 commit 0d7843e

14 files changed

Lines changed: 737 additions & 609 deletions

docs_build/dev/BUILD_PR.md

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1-
# PR_26177_DELTA_054-random-utility
1+
# PR_26177_DELTA_055-random-seed-enhancements
22

33
## Purpose
44

5-
Add a nondeterministic `Random` utility with the same public convenience API shape as `RandomSeed`.
5+
Enhance `RandomSeed` with matching procedural convenience methods.
66

77
## Source Of Truth
88

9-
This `BUILD_PR.md`, `PLAN_PR.md`, the user request, and `docs_build/dev/ProjectInstructions.zip` are the source of truth for `PR_26177_DELTA_054-random-utility`.
9+
This `BUILD_PR.md`, `PLAN_PR.md`, the user request, and `docs_build/dev/ProjectInstructions.zip` are the source of truth for `PR_26177_DELTA_055-random-seed-enhancements`.
1010

1111
## OWNER Override And Team Assignment
1212

13-
OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_054-random-utility`.
13+
OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_055-random-seed-enhancements`.
1414

1515
Team Delta owns Shared JS, runtime utilities, technical debt remediation, and runtime test coverage.
1616

1717
## Stack
1818

19-
- Base branch: `PR_26177_DELTA_053-random-shared-helpers`
20-
- This PR depends on the internal random helper module from PR_053.
19+
- Base branch: `PR_26177_DELTA_054-random-utility`
20+
- This PR depends on the shared helper module from PR_053 and the stack context from PR_054.
2121

2222
## Exact Scope
2323

24-
- Add `Random` utility.
25-
- Include:
26-
- `Random.next()`
27-
- `Random.nextInt(min, max)`
28-
- `Random.nextFloat(min, max)`
29-
- `Random.pick(array)`
30-
- `Random.shuffle(array)`
31-
- `Random.chance(percent)`
32-
- `Random.weightedPick(weightedItems)`
33-
- `Random.uuid()`
34-
- Prefer `crypto.getRandomValues()` when available.
35-
- Use `Math.random()` only as compatibility fallback.
36-
- No deterministic seed support in `Random`.
37-
- No browser storage.
24+
- Update `RandomSeed` to use shared helper logic where appropriate.
25+
- Add:
26+
- `shuffle(array)`
27+
- `chance(percent)`
28+
- `weightedPick(weightedItems)`
29+
- `saveState()`
30+
- `restoreState(state)`
31+
- Preserve existing `RandomSeed` sequence compatibility.
32+
- Same seed must still reproduce same sequence.
33+
- Reseeding must still reproduce same sequence.
34+
- Add targeted unit tests for new methods.
35+
- No adoption changes in existing game logic.
3836
- No UI changes.
39-
- Add JSDoc.
40-
- Add targeted unit tests.
4137
- Create required Codex reports under `docs_build/dev/reports/`.
4238
- Create repo-structured delta ZIP under `tmp/`.
4339

@@ -47,22 +43,21 @@ Team Delta owns Shared JS, runtime utilities, technical debt remediation, and ru
4743
- `docs_build/dev/BUILD_PR.md`
4844
- `docs_build/dev/ProjectInstructions/team_assignments/TEAM_ASSIGNMENTS.md`
4945
- `docs_build/dev/ProjectInstructions/team_assignments/ACTIVE_TEAM_REGISTRY.md`
50-
- `src/shared/math/Random.js`
51-
- `tests/shared/Random.test.mjs`
52-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility.md`
53-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_branch-validation.md`
54-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_requirement-checklist.md`
55-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_validation-lane.md`
56-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_manual-validation-notes.md`
57-
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_instruction-compliance-checklist.md`
46+
- `src/shared/math/RandomSeed.js`
47+
- `tests/shared/RandomSeed.test.mjs`
48+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements.md`
49+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_branch-validation.md`
50+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_requirement-checklist.md`
51+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_validation-lane.md`
52+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_manual-validation-notes.md`
53+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_instruction-compliance-checklist.md`
5854
- `docs_build/dev/reports/codex_review.diff`
5955
- `docs_build/dev/reports/codex_changed_files.txt`
6056

6157
## Out Of Scope
6258

63-
- No deterministic seed support in `Random`.
59+
- No seeded `next()` algorithm changes.
6460
- No existing game logic adoption changes.
65-
- No existing `Math.random()` call-site replacements.
6661
- No UI changes.
6762
- No browser storage changes.
6863
- No API changes.
@@ -75,9 +70,9 @@ Team Delta owns Shared JS, runtime utilities, technical debt remediation, and ru
7570
Run exactly:
7671

7772
```powershell
78-
node ./scripts/run-node-test-files.mjs tests/shared/Random.test.mjs tests/shared/RandomHelpers.test.mjs
79-
node --check src/shared/math/Random.js
80-
node --check tests/shared/Random.test.mjs
73+
node ./scripts/run-node-test-files.mjs tests/shared/RandomSeed.test.mjs tests/shared/RandomHelpers.test.mjs
74+
node --check src/shared/math/RandomSeed.js
75+
node --check tests/shared/RandomSeed.test.mjs
8176
git diff --check
8277
```
8378

@@ -88,5 +83,5 @@ Playwright is not required because this PR does not change UI or browser runtime
8883
Create repo-structured delta ZIP:
8984

9085
```text
91-
tmp/PR_26177_DELTA_054-random-utility_delta.zip
86+
tmp/PR_26177_DELTA_055-random-seed-enhancements_delta.zip
9287
```

docs_build/dev/PLAN_PR.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
1-
# PLAN_PR: PR_26177_DELTA_054-random-utility
1+
# PLAN_PR: PR_26177_DELTA_055-random-seed-enhancements
22

33
## Purpose
44

5-
Add a nondeterministic `Random` utility with the same public convenience API shape as `RandomSeed`.
5+
Enhance `RandomSeed` with matching procedural convenience methods.
66

77
## Owner And Assignment
88

99
- Team: Delta
10-
- OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_054-random-utility`.
11-
- Stack base: `PR_26177_DELTA_053-random-shared-helpers`.
10+
- OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_055-random-seed-enhancements`.
11+
- Stack base: `PR_26177_DELTA_054-random-utility`.
1212

1313
## Scope
1414

15-
- Add `Random` utility.
16-
- Include:
17-
- `Random.next()`
18-
- `Random.nextInt(min, max)`
19-
- `Random.nextFloat(min, max)`
20-
- `Random.pick(array)`
21-
- `Random.shuffle(array)`
22-
- `Random.chance(percent)`
23-
- `Random.weightedPick(weightedItems)`
24-
- `Random.uuid()`
25-
- Prefer `crypto.getRandomValues()` when available.
26-
- Use `Math.random()` only as compatibility fallback.
27-
- No deterministic seed support in `Random`.
28-
- No browser storage.
15+
- Update `RandomSeed` to use shared helper logic where appropriate.
16+
- Add:
17+
- `shuffle(array)`
18+
- `chance(percent)`
19+
- `weightedPick(weightedItems)`
20+
- `saveState()`
21+
- `restoreState(state)`
22+
- Preserve existing `RandomSeed` sequence compatibility.
23+
- Same seed must still reproduce same sequence.
24+
- Reseeding must still reproduce same sequence.
25+
- Add targeted unit tests for new methods.
26+
- No adoption changes in existing game logic.
2927
- No UI changes.
30-
- Add JSDoc.
31-
- Add targeted unit tests.
3228

3329
## Implementation Plan
3430

35-
1. Add `src/shared/math/Random.js`.
36-
2. Reuse internal helper functions from `src/shared/math/randomHelpers.js`.
37-
3. Add `tests/shared/Random.test.mjs`.
38-
4. Validate crypto preference, Math fallback, utility methods, UUID shape, and absence of seed API.
31+
1. Update `src/shared/math/RandomSeed.js` to reuse `randomHelpers.js` for procedural helper methods.
32+
2. Keep the existing seeded `next()` algorithm unchanged.
33+
3. Add state save/restore methods.
34+
4. Extend `tests/shared/RandomSeed.test.mjs` with sequence compatibility, new method, and state tests.
3935
5. Produce required PR reports and repo-structured ZIP.
4036

4137
## Acceptance Criteria
4238

43-
- `Random` exposes the required static convenience methods.
44-
- `Random` does not expose deterministic seed support.
45-
- `Random` uses `crypto.getRandomValues()` when available.
46-
- `Math.random()` is used only when crypto random values are unavailable.
39+
- Existing seeded sequence values remain compatible.
40+
- Same seed and reseeding behavior remain deterministic.
41+
- New procedural methods use the same seeded random stream.
42+
- State save/restore resumes the sequence from the saved point.

docs_build/dev/ProjectInstructions/team_assignments/ACTIVE_TEAM_REGISTRY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If a team has no assignment, no active branch, and no active PR, it is inactive
3131
| Team Alfa | none | none | none | Available | Active ownership lane |
3232
| Team Bravo | none | none | none | Available | Active ownership lane |
3333
| Team Charlie | none | none | none | Available | Active ownership lane |
34-
| Team Delta | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | Active | OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_054-random-utility |
34+
| Team Delta | PR_26177_DELTA_055-random-seed-enhancements | PR_26177_DELTA_055-random-seed-enhancements | PR_26177_DELTA_055-random-seed-enhancements | Active | OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_055-random-seed-enhancements |
3535
| Team Golf | none | none | none | Available | Replacement active ownership lane for retired Team Gamma |
3636
| Team OWNER | none | none | none | Available | Governance Phase 1 complete |
3737

docs_build/dev/ProjectInstructions/team_assignments/TEAM_ASSIGNMENTS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| Team Alfa | none | none | none | Available |
88
| Team Bravo | none | none | none | Available |
99
| Team Charlie | none | none | none | Available |
10-
| Team Delta | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | Active |
10+
| Team Delta | PR_26177_DELTA_055-random-seed-enhancements | PR_26177_DELTA_055-random-seed-enhancements | PR_26177_DELTA_055-random-seed-enhancements | Active |
1111
| Team Golf | none | none | none | Available |
1212
| Team OWNER | none | none | none | Available |
1313

@@ -50,13 +50,13 @@ Current OWNER clarification:
5050

5151
Status: Active
5252

53-
Active assignment: PR_26177_DELTA_054-random-utility.
53+
Active assignment: PR_26177_DELTA_055-random-seed-enhancements.
5454

55-
Active branch: PR_26177_DELTA_054-random-utility.
55+
Active branch: PR_26177_DELTA_055-random-seed-enhancements.
5656

57-
Active PR: PR_26177_DELTA_054-random-utility.
57+
Active PR: PR_26177_DELTA_055-random-seed-enhancements.
5858

59-
OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_054-random-utility.
59+
OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_055-random-seed-enhancements.
6060

6161
## Team Bravo
6262

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements
2+
3+
Date: 2026-06-26
4+
Team: Delta
5+
Scope: RandomSeed procedural enhancements and targeted unit tests
6+
Status: PASS
7+
8+
## Summary
9+
10+
- Updated `RandomSeed` to use shared helper logic for `nextInt`, `nextFloat`, and `pick`.
11+
- Added seeded procedural methods: `shuffle`, `chance`, and `weightedPick`.
12+
- Added `saveState()` and `restoreState(state)` for deterministic sequence checkpointing.
13+
- Preserved the existing `RandomSeed.next()` algorithm.
14+
- Added a hardcoded compatibility check for the existing `RandomSeed(42)` sequence.
15+
- Verified same-seed and reseeding reproducibility still pass.
16+
- Added targeted tests for the new methods and state restore behavior.
17+
- No existing game logic adoption changes or UI changes were made.
18+
19+
## Branch Validation
20+
21+
PASS. Branch `PR_26177_DELTA_055-random-seed-enhancements` was created from `PR_26177_DELTA_054-random-utility`.
22+
23+
## Changed Files
24+
25+
- `docs_build/dev/PLAN_PR.md`
26+
- `docs_build/dev/BUILD_PR.md`
27+
- `docs_build/dev/ProjectInstructions/team_assignments/TEAM_ASSIGNMENTS.md`
28+
- `docs_build/dev/ProjectInstructions/team_assignments/ACTIVE_TEAM_REGISTRY.md`
29+
- `src/shared/math/RandomSeed.js`
30+
- `tests/shared/RandomSeed.test.mjs`
31+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements.md`
32+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_branch-validation.md`
33+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_requirement-checklist.md`
34+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_validation-lane.md`
35+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_manual-validation-notes.md`
36+
- `docs_build/dev/reports/PR_26177_DELTA_055-random-seed-enhancements_instruction-compliance-checklist.md`
37+
- `docs_build/dev/reports/codex_changed_files.txt`
38+
- `docs_build/dev/reports/codex_review.diff`
39+
40+
## Validation
41+
42+
- PASS: `node ./scripts/run-node-test-files.mjs tests/shared/RandomSeed.test.mjs tests/shared/RandomHelpers.test.mjs`
43+
- PASS: `node --check src/shared/math/RandomSeed.js`
44+
- PASS: `node --check tests/shared/RandomSeed.test.mjs`
45+
- PASS: `git diff --check`
46+
- SKIP: Playwright was not run because this PR does not change UI or browser runtime flows.
47+
48+
## Artifact
49+
50+
- `tmp/PR_26177_DELTA_055-random-seed-enhancements_delta.zip`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements Branch Validation
2+
3+
Status: PASS
4+
5+
## Start Gates
6+
7+
- PASS: PR_055 branch was created from `PR_26177_DELTA_054-random-utility`.
8+
- PASS: Stack base was clean before branch creation.
9+
- PASS: Branch name is `PR_26177_DELTA_055-random-seed-enhancements`.
10+
11+
## Scope Confirmation
12+
13+
- PASS: Work is assigned to Team Delta.
14+
- PASS: Work is limited to `RandomSeed` procedural enhancements, targeted tests, PR docs, reports, and ZIP packaging.
15+
- PASS: No existing game logic adoption changes, UI changes, API changes, database changes, or unrelated cleanup were made.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements Instruction Compliance Checklist
2+
3+
| Instruction | Status | Notes |
4+
|---|---:|---|
5+
| Continue stacked Random PR sequence | PASS | Branch was created from PR_054. |
6+
| Keep one PR purpose only | PASS | Scope is RandomSeed enhancements. |
7+
| Preserve sequence compatibility | PASS | Existing `RandomSeed(42)` sequence is asserted in tests. |
8+
| No adoption changes in existing game logic | PASS | No call sites were changed. |
9+
| No UI changes | PASS | No UI files changed. |
10+
| Produce required reports | PASS | Reports were added under `docs_build/dev/reports/`. |
11+
| Produce repo-structured ZIP under `tmp/` | PASS | ZIP path is `tmp/PR_26177_DELTA_055-random-seed-enhancements_delta.zip`. |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements Manual Validation Notes
2+
3+
Status: PASS
4+
5+
Manual review confirmed:
6+
7+
- `RandomSeed.next()` was not changed.
8+
- The hardcoded `RandomSeed(42)` sequence remains compatible with PR_052 behavior.
9+
- New procedural methods consume the same seeded stream through shared helpers.
10+
- `saveState()` and `restoreState(state)` are in-memory and serializable; no browser storage was added.
11+
- No UI, API, database, or existing game logic adoption files changed.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements Requirement Checklist
2+
3+
| Requirement | Status | Notes |
4+
|---|---:|---|
5+
| Update `RandomSeed` to use shared helper logic where appropriate | PASS | `nextInt`, `nextFloat`, `pick`, and new methods use `randomHelpers.js`. |
6+
| Add `shuffle(array)` | PASS | Added seeded shuffle method. |
7+
| Add `chance(percent)` | PASS | Added seeded chance method. |
8+
| Add `weightedPick(weightedItems)` | PASS | Added seeded weighted pick method. |
9+
| Add `saveState()` | PASS | Added serializable state capture. |
10+
| Add `restoreState(state)` | PASS | Added state restore with validation. |
11+
| Preserve existing `RandomSeed` sequence compatibility | PASS | Hardcoded `RandomSeed(42)` sequence check passes. |
12+
| Same seed still reproduces same sequence | PASS | Existing targeted test still passes. |
13+
| Reseeding still reproduces same sequence | PASS | Existing targeted test still passes. |
14+
| Add targeted unit tests for new methods | PASS | Extended `tests/shared/RandomSeed.test.mjs`. |
15+
| No adoption changes in existing game logic | PASS | No game logic call sites changed. |
16+
| No UI changes | PASS | No UI files changed. |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# PR_26177_DELTA_055-random-seed-enhancements Validation Lane
2+
3+
Status: PASS
4+
5+
## Commands
6+
7+
```powershell
8+
node ./scripts/run-node-test-files.mjs tests/shared/RandomSeed.test.mjs tests/shared/RandomHelpers.test.mjs
9+
node --check src/shared/math/RandomSeed.js
10+
node --check tests/shared/RandomSeed.test.mjs
11+
git diff --check
12+
```
13+
14+
## Results
15+
16+
- PASS: `tests/shared/RandomSeed.test.mjs`
17+
- PASS: `tests/shared/RandomHelpers.test.mjs`
18+
- PASS: `src/shared/math/RandomSeed.js` syntax check
19+
- PASS: `tests/shared/RandomSeed.test.mjs` syntax check
20+
- PASS: `git diff --check`
21+
22+
## Playwright
23+
24+
SKIP. Playwright was not run because this PR does not change UI or browser runtime flows.

0 commit comments

Comments
 (0)