fix: widen seed/state types in random/base/randi#12568
Draft
Planeshifter wants to merge 1 commit into
Draft
Conversation
The `Options.name` field allows `'minstd'` and `'minstd-shuffle'` in addition to `'mt19937'`, and `randi` delegates `seed`/`state` to the selected underlying PRNG. When a MINSTD generator is selected, `.state` returns an `Int32Array` (`PRNGStateMINSTD`), which the MT19937-only `Uint32Array` (`PRNGStateMT19937`) type rejected. Widen the `Options` `seed`/`state` and the `PRNG` interface `seed`/`state` to include the MINSTD variants, matching the sibling random/base/randu declaration. (The `state` widening is the load-bearing correctness fix; the `seed` union is included for consistency, since `PRNGSeedMINSTD` and `PRNGSeedMT19937` are structurally identical.)
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
seedandstatetypes inrandom/base/randito include the MINSTD variants.The
Options.namefield already permits MINSTD generators:and
randidelegatesseed/stateto the selected underlying PRNG (getState() { return rand.state; }). Whennameis'minstd'/'minstd-shuffle',.statereturns anInt32Array(PRNGStateMINSTD), which the MT19937-onlyUint32Array(PRNGStateMT19937) type rejected.This widens all four members — the
Optionsseed/stateand thePRNGinterfaceseed/state— to include the MINSTD variants, matching the siblingrandom/base/randudeclaration (which already uses the union):The
statewidening is the load-bearing correctness fix; theseedunion is included for consistency withrandu, sincePRNGSeedMINSTDandPRNGSeedMT19937are structurally identical (number | ArrayLike<number>).Related Issues
No.
Questions
No.
Other
Identified during a TypeScript-declaration audit of the
@stdlib/randomnamespace and verified againstlib/factory.js,lib/prngs.js, and the@stdlib/types/randomseed/state definitions.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
A TypeScript-declaration audit surfaced this issue using Claude Code; the finding was independently verified against the implementation and the
base/randureference, and reviewed by myself before submitting.@stdlib-js/reviewers