Skip to content

fix: widen seed/state types in random/base/randi#12568

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-base-randi-state-type
Draft

fix: widen seed/state types in random/base/randi#12568
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-base-randi-state-type

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • widens the seed and state types in random/base/randi to include the MINSTD variants.

The Options.name field already permits MINSTD generators:

name?: 'mt19937' | 'minstd' | 'minstd-shuffle';

and randi delegates seed/state to the selected underlying PRNG (getState() { return rand.state; }). When name is 'minstd'/'minstd-shuffle', .state returns an Int32Array (PRNGStateMINSTD), which the MT19937-only Uint32Array (PRNGStateMT19937) type rejected.

This widens all four members — the Options seed/state and the PRNG interface seed/state — to include the MINSTD variants, matching the sibling random/base/randu declaration (which already uses the union):

seed?: random.PRNGSeedMT19937 | random.PRNGSeedMINSTD;
state?: random.PRNGStateMT19937 | random.PRNGStateMINSTD;

The state widening is the load-bearing correctness fix; the seed union is included for consistency with randu, since PRNGSeedMINSTD and PRNGSeedMT19937 are structurally identical (number | ArrayLike<number>).

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Identified during a TypeScript-declaration audit of the @stdlib/random namespace and verified against lib/factory.js, lib/prngs.js, and the @stdlib/types/random seed/state definitions.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

A TypeScript-declaration audit surfaced this issue using Claude Code; the finding was independently verified against the implementation and the base/randu reference, and reviewed by myself before submitting.


@stdlib-js/reviewers

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.)
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
random/base/randi $\color{green}381/381$
$\color{green}+100.00\%$
$\color{green}34/34$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}381/381$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants