Skip to content

fix: widen instance seed/state types in random/streams/randu#12567

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-streams-randu-state-type
Draft

fix: widen instance seed/state types in random/streams/randu#12567
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-streams-randu-state-type

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • widens the instance seed and state member types in random/streams/randu to include the MINSTD variants.

The Options interface already permits selecting a MINSTD generator:

name?: 'mt19937' | 'minstd' | 'minstd-shuffle';
seed?: random.PRNGSeedMT19937 | random.PRNGSeedMINSTD;
state?: random.PRNGStateMT19937 | random.PRNGStateMINSTD;

and the stream forwards seed/state from the underlying PRNG (@stdlib/random/base/randu), which selects a MINSTD generator when name is 'minstd'/'minstd-shuffle'. A MINSTD state is an Int32Array (PRNGStateMINSTD), distinct from MT19937's Uint32Array. However, the instance members were typed MT19937-only:

readonly seed: random.PRNGSeedMT19937;          // before
state: random.PRNGStateMT19937;                  // before

so the declared types rejected valid MINSTD shapes. This widens both to match the Options interface and the sibling random/base/randu declaration (which already uses the union):

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

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/main.js, the base/randu factory, 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` interface already allows `name` to be `'minstd'` or
`'minstd-shuffle'` in addition to `'mt19937'`, and the stream forwards
`seed`/`state` from the underlying PRNG (`@stdlib/random/base/randu`),
which selects a MINSTD generator for those names. A MINSTD state is an
`Int32Array` (`PRNGStateMINSTD`), but the instance `seed`/`state`
members were typed as MT19937-only, so the declared types rejected
valid MINSTD shapes. Widen both to include the MINSTD variants, matching
the `Options` interface and the sibling random/base/randu declaration.
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
random/streams/randu $\color{green}768/768$
$\color{green}+100.00\%$
$\color{green}83/83$
$\color{green}+100.00\%$
$\color{green}14/14$
$\color{green}+100.00\%$
$\color{green}768/768$
$\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