Skip to content

Commit 7c8d20e

Browse files
authored
Merge pull request #206 from ToolboxAid/PR_26177_DELTA_054-random-utility
PR_26177_DELTA_054-random-utility
2 parents 145aacf + 2e39164 commit 7c8d20e

14 files changed

Lines changed: 920 additions & 497 deletions

docs_build/dev/BUILD_PR.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
# PR_26177_DELTA_053-random-shared-helpers
1+
# PR_26177_DELTA_054-random-utility
22

33
## Purpose
44

5-
Create shared internal helper logic for random utility operations.
5+
Add a nondeterministic `Random` utility with the same public convenience API shape as `RandomSeed`.
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_053-random-shared-helpers`.
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`.
1010

1111
## OWNER Override And Team Assignment
1212

13-
OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_053-random-shared-helpers`.
13+
OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_054-random-utility`.
1414

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

17+
## Stack
18+
19+
- Base branch: `PR_26177_DELTA_053-random-shared-helpers`
20+
- This PR depends on the internal random helper module from PR_053.
21+
1722
## Exact Scope
1823

19-
- Add internal/shared helper functions for:
20-
- `nextInt(randomNext, min, max)`
21-
- `nextFloat(randomNext, min, max)`
22-
- `pick(randomNext, array)`
23-
- `shuffle(randomNext, array)`
24-
- `chance(randomNext, percent)`
25-
- `weightedPick(randomNext, weightedItems)`
26-
- Helper must consume a `randomNext` function returning float `>= 0` and `< 1`.
27-
- Do not expose this as Creator-facing API.
28-
- Do not change existing `RandomSeed` behavior.
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.
38+
- No UI changes.
39+
- Add JSDoc.
2940
- Add targeted unit tests.
3041
- Create required Codex reports under `docs_build/dev/reports/`.
3142
- Create repo-structured delta ZIP under `tmp/`.
@@ -36,21 +47,21 @@ Team Delta owns Shared JS, runtime utilities, technical debt remediation, and ru
3647
- `docs_build/dev/BUILD_PR.md`
3748
- `docs_build/dev/ProjectInstructions/team_assignments/TEAM_ASSIGNMENTS.md`
3849
- `docs_build/dev/ProjectInstructions/team_assignments/ACTIVE_TEAM_REGISTRY.md`
39-
- `src/shared/math/randomHelpers.js`
40-
- `tests/shared/RandomHelpers.test.mjs`
41-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers.md`
42-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_branch-validation.md`
43-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_requirement-checklist.md`
44-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_validation-lane.md`
45-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_manual-validation-notes.md`
46-
- `docs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_instruction-compliance-checklist.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`
4758
- `docs_build/dev/reports/codex_review.diff`
4859
- `docs_build/dev/reports/codex_changed_files.txt`
4960

5061
## Out Of Scope
5162

52-
- No Creator-facing API exposure.
53-
- No existing `RandomSeed` behavior changes.
63+
- No deterministic seed support in `Random`.
64+
- No existing game logic adoption changes.
5465
- No existing `Math.random()` call-site replacements.
5566
- No UI changes.
5667
- No browser storage changes.
@@ -64,9 +75,9 @@ Team Delta owns Shared JS, runtime utilities, technical debt remediation, and ru
6475
Run exactly:
6576

6677
```powershell
67-
node ./scripts/run-node-test-files.mjs tests/shared/RandomHelpers.test.mjs tests/shared/RandomSeed.test.mjs
68-
node --check src/shared/math/randomHelpers.js
69-
node --check tests/shared/RandomHelpers.test.mjs
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
7081
git diff --check
7182
```
7283

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

7990
```text
80-
tmp/PR_26177_DELTA_053-random-shared-helpers_delta.zip
91+
tmp/PR_26177_DELTA_054-random-utility_delta.zip
8192
```

docs_build/dev/PLAN_PR.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1-
# PLAN_PR: PR_26177_DELTA_053-random-shared-helpers
1+
# PLAN_PR: PR_26177_DELTA_054-random-utility
22

33
## Purpose
44

5-
Create shared internal helper logic for random utility operations.
5+
Add a nondeterministic `Random` utility with the same public convenience API shape as `RandomSeed`.
66

77
## Owner And Assignment
88

99
- Team: Delta
10-
- OWNER override approved: Continue Team Delta random utility stack with `PR_26177_DELTA_053-random-shared-helpers`.
11-
- Ownership fit: Team Delta owns Shared JS, runtime utilities, technical debt remediation, and runtime test coverage.
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`.
1212

1313
## Scope
1414

15-
- Add internal/shared helper functions for:
16-
- `nextInt(randomNext, min, max)`
17-
- `nextFloat(randomNext, min, max)`
18-
- `pick(randomNext, array)`
19-
- `shuffle(randomNext, array)`
20-
- `chance(randomNext, percent)`
21-
- `weightedPick(randomNext, weightedItems)`
22-
- Helper functions must consume a `randomNext` function returning a float `>= 0` and `< 1`.
23-
- Do not expose these helpers as Creator-facing API.
24-
- Do not change existing `RandomSeed` behavior.
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.
29+
- No UI changes.
30+
- Add JSDoc.
2531
- Add targeted unit tests.
2632

2733
## Implementation Plan
2834

29-
1. Add `src/shared/math/randomHelpers.js`.
30-
2. Add `tests/shared/RandomHelpers.test.mjs`.
31-
3. Validate helper behavior and input guards with targeted unit tests.
32-
4. Preserve current `RandomSeed` implementation and tests unchanged.
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.
3339
5. Produce required PR reports and repo-structured ZIP.
3440

3541
## Acceptance Criteria
3642

37-
- Helpers use only the supplied `randomNext` source.
38-
- Integer, float, pick, shuffle, chance, and weighted pick operations are covered.
39-
- Invalid `randomNext`, ranges, arrays, percentages, and weighted item inputs reject predictably.
40-
- Existing `RandomSeed` behavior remains unchanged.
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.

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_053-random-shared-helpers | PR_26177_DELTA_053-random-shared-helpers | PR_26177_DELTA_053-random-shared-helpers | Active | OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_053-random-shared-helpers |
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 |
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_053-random-shared-helpers | PR_26177_DELTA_053-random-shared-helpers | PR_26177_DELTA_053-random-shared-helpers | Active |
10+
| Team Delta | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | PR_26177_DELTA_054-random-utility | 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_053-random-shared-helpers.
53+
Active assignment: PR_26177_DELTA_054-random-utility.
5454

55-
Active branch: PR_26177_DELTA_053-random-shared-helpers.
55+
Active branch: PR_26177_DELTA_054-random-utility.
5656

57-
Active PR: PR_26177_DELTA_053-random-shared-helpers.
57+
Active PR: PR_26177_DELTA_054-random-utility.
5858

59-
OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_053-random-shared-helpers.
59+
OWNER override approved: Continue Team Delta random utility stack with PR_26177_DELTA_054-random-utility.
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_054-random-utility
2+
3+
Date: 2026-06-26
4+
Team: Delta
5+
Scope: Nondeterministic shared Random utility and targeted unit tests
6+
Status: PASS
7+
8+
## Summary
9+
10+
- Added `Random` as a nondeterministic shared random utility in `src/shared/math/Random.js`.
11+
- Added static convenience methods matching the public shape requested: `next`, `nextInt`, `nextFloat`, `pick`, `shuffle`, `chance`, `weightedPick`, and `uuid`.
12+
- Reused internal helper logic from PR_053.
13+
- Preferred `crypto.getRandomValues()` when available.
14+
- Used `Math.random()` only as compatibility fallback when crypto random values are unavailable.
15+
- Did not add deterministic seed support to `Random`.
16+
- Added targeted unit tests in `tests/shared/Random.test.mjs`.
17+
- No browser storage, UI, API, database, or existing game logic adoption changes were made.
18+
19+
## Branch Validation
20+
21+
PASS. Branch `PR_26177_DELTA_054-random-utility` was created from `PR_26177_DELTA_053-random-shared-helpers`.
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/Random.js`
30+
- `tests/shared/Random.test.mjs`
31+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility.md`
32+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_branch-validation.md`
33+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_requirement-checklist.md`
34+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_validation-lane.md`
35+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_manual-validation-notes.md`
36+
- `docs_build/dev/reports/PR_26177_DELTA_054-random-utility_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/Random.test.mjs tests/shared/RandomHelpers.test.mjs`
43+
- PASS: `node --check src/shared/math/Random.js`
44+
- PASS: `node --check tests/shared/Random.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_054-random-utility_delta.zip`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# PR_26177_DELTA_054-random-utility Branch Validation
2+
3+
Status: PASS
4+
5+
## Start Gates
6+
7+
- PASS: PR_054 branch was created from `PR_26177_DELTA_053-random-shared-helpers`.
8+
- PASS: Stack base was clean before branch creation.
9+
- PASS: Branch name is `PR_26177_DELTA_054-random-utility`.
10+
11+
## Scope Confirmation
12+
13+
- PASS: Work is assigned to Team Delta.
14+
- PASS: Work is limited to nondeterministic Random utility, targeted tests, PR docs, reports, and ZIP packaging.
15+
- PASS: No deterministic seed support, UI, browser storage, API, database, or unrelated cleanup changes were made.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PR_26177_DELTA_054-random-utility Instruction Compliance Checklist
2+
3+
| Instruction | Status | Notes |
4+
|---|---:|---|
5+
| Continue stacked Random PR sequence | PASS | Branch was created from PR_053. |
6+
| Keep one PR purpose only | PASS | Scope is nondeterministic Random utility. |
7+
| Use shared helper logic from PR_053 | PASS | Random delegates convenience methods to `randomHelpers.js`. |
8+
| Do not add deterministic seed support | PASS | No seed API or seed state was added. |
9+
| No UI/browser storage/API/database changes | PASS | No such files or behaviors 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_054-random-utility_delta.zip`. |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PR_26177_DELTA_054-random-utility Manual Validation Notes
2+
3+
Status: PASS
4+
5+
Manual review confirmed:
6+
7+
- `Random` is nondeterministic and does not support seeding.
8+
- `Random` prefers `crypto.getRandomValues()` and falls back to `Math.random()` only when crypto random values are unavailable.
9+
- Public methods match the requested convenience API shape.
10+
- `Random` does not use browser storage and is not wired into UI or existing game logic.
11+
- Tests mock crypto and Math fallback sources and restore globals after assertions.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# PR_26177_DELTA_054-random-utility Requirement Checklist
2+
3+
| Requirement | Status | Notes |
4+
|---|---:|---|
5+
| Add `Random` utility | PASS | Added `src/shared/math/Random.js`. |
6+
| Include `Random.next()` | PASS | Static method added. |
7+
| Include `Random.nextInt(min, max)` | PASS | Static method added using shared helper. |
8+
| Include `Random.nextFloat(min, max)` | PASS | Static method added using shared helper. |
9+
| Include `Random.pick(array)` | PASS | Static method added using shared helper. |
10+
| Include `Random.shuffle(array)` | PASS | Static method added using shared helper. |
11+
| Include `Random.chance(percent)` | PASS | Static method added using shared helper. |
12+
| Include `Random.weightedPick(weightedItems)` | PASS | Static method added using shared helper. |
13+
| Include `Random.uuid()` | PASS | Static RFC 4122 v4 UUID method added. |
14+
| Prefer `crypto.getRandomValues()` when available | PASS | `Random.next()` and `Random.uuid()` use crypto random values when present. |
15+
| Use `Math.random()` only as compatibility fallback | PASS | Fallback path is used only when crypto random values are unavailable. |
16+
| No deterministic seed support in `Random` | PASS | No `seed` method or seed state added. |
17+
| No browser storage | PASS | No storage usage added. |
18+
| No UI changes | PASS | No UI files changed. |
19+
| Add JSDoc | PASS | Added class and public method JSDoc. |
20+
| Add targeted unit tests | PASS | Added `tests/shared/Random.test.mjs`. |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# PR_26177_DELTA_054-random-utility Validation Lane
2+
3+
Status: PASS
4+
5+
## Commands
6+
7+
```powershell
8+
node ./scripts/run-node-test-files.mjs tests/shared/Random.test.mjs tests/shared/RandomHelpers.test.mjs
9+
node --check src/shared/math/Random.js
10+
node --check tests/shared/Random.test.mjs
11+
git diff --check
12+
```
13+
14+
## Results
15+
16+
- PASS: `tests/shared/Random.test.mjs`
17+
- PASS: `tests/shared/RandomHelpers.test.mjs`
18+
- PASS: `src/shared/math/Random.js` syntax check
19+
- PASS: `tests/shared/Random.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)