PR_26177_DELTA_053-random-shared-helpers#205
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7cb0fa085
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assertOrderedRange(min, max); | ||
| return min + readRandomValue(randomNext) * (max - min); |
There was a problem hiding this comment.
Reject degenerate float ranges
When callers pass an equal min and max, assertOrderedRange permits the range and this returns min, but that value is equal to the exclusive upper bound and is therefore outside the documented [min, max) contract. For example, nextFloat(() => 0, 5, 5) returns 5 instead of rejecting an empty float interval, so callers can receive an out-of-range value for degenerate ranges.
Useful? React with 👍 / 👎.
|
|
||
| function readRandomValue(randomNext) { | ||
| assertRandomNext(randomNext); | ||
| const value = Number(randomNext()); |
There was a problem hiding this comment.
Reject non-number random results
Because the helper coerces the random source result with Number(...), invalid implementations that return values like null, "", or numeric strings are accepted as valid rolls instead of failing the documented randomNext contract. For example, nextInt(() => null, 1, 3) currently returns 1, which can silently bias every caller toward the lower bound when a broken random source returns a non-number.
Useful? React with 👍 / 👎.
PR_26177_DELTA_053-random-shared-helpers
Date: 2026-06-26
Team: Delta
Scope: Shared internal random helper logic and targeted unit tests
Status: PASS
Summary
src/shared/math/randomHelpers.js.nextInt,nextFloat,pick,shuffle,chance, andweightedPick.randomNextfunctions returning floats>= 0and< 1.RandomSeedbehavior and did not change its implementation in this PR.tests/shared/RandomHelpers.test.mjs.Branch Validation
PASS. Branch
PR_26177_DELTA_053-random-shared-helperswas created from clean synchronizedmainafter PR_052 merged.Changed Files
docs_build/dev/PLAN_PR.mddocs_build/dev/BUILD_PR.mddocs_build/dev/ProjectInstructions/team_assignments/TEAM_ASSIGNMENTS.mddocs_build/dev/ProjectInstructions/team_assignments/ACTIVE_TEAM_REGISTRY.mdsrc/shared/math/randomHelpers.jstests/shared/RandomHelpers.test.mjsdocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers.mddocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_branch-validation.mddocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_requirement-checklist.mddocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_validation-lane.mddocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_manual-validation-notes.mddocs_build/dev/reports/PR_26177_DELTA_053-random-shared-helpers_instruction-compliance-checklist.mddocs_build/dev/reports/codex_changed_files.txtdocs_build/dev/reports/codex_review.diffValidation
node ./scripts/run-node-test-files.mjs tests/shared/RandomHelpers.test.mjs tests/shared/RandomSeed.test.mjsnode --check src/shared/math/randomHelpers.jsnode --check tests/shared/RandomHelpers.test.mjsgit diff --checkArtifact
tmp/PR_26177_DELTA_053-random-shared-helpers_delta.zip