Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mt19937.factory does not accept 0 as a seed #1963

Closed
2 tasks done
charredUtensil opened this issue Mar 20, 2024 · 3 comments
Closed
2 tasks done

mt19937.factory does not accept 0 as a seed #1963

charredUtensil opened this issue Mar 20, 2024 · 3 comments
Labels
Bug Something isn't working. Documentation Improvements, additions, or changes to documentation.

Comments

@charredUtensil
Copy link

Description

Calling mt19937.factory({seed:0}) causes:

factory.js:427 Uncaught TypeError: invalid option. `seed` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: ``.
    at Function.factory (factory.js:427:1)
    at <anonymous>:1:9

However, the documentation states the valid range for a seed is [0, 4294967295]

I am using the mt19937 and beta libraries to generate pseudorandom values for a map generator. As part of that, I'm actually using mt19937 to generate random seeds that I feed back into mt19937 to generate more independent PRNGs, so it's a bit odd that the range of valid seeds is off by 1 from the range of output values. I suspect the documentation is correct and the generator is wrong.

Related Issues

Related issues # , # , and # .

Questions

No.

Demo

No response

Reproduction

import mt19937 from "@stdlib/random-base-mt19937";
mt19937.factory({seed:0})


### Expected Results

```shell
A working pseudorandom number generator

Actual Results

factory.js:427 Uncaught TypeError: invalid option. `seed` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: ``.
    at Function.factory (factory.js:427:1)
    at <anonymous>:1:9

Version

0.2.1

Environments

Firefox, Chrome

Browser Version

No response

Node.js / npm Version

No response

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
@stdlib-bot
Copy link
Contributor

👋 Hi there! 👋

And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

@kgryte
Copy link
Member

kgryte commented Mar 20, 2024

@charredUtensil I believe the documentation is wrong here and the implementation correct. It is fairly common for PRNGs to not allow 0 seeds, as this can lead to degenerate starting states. From the original paper,

Since any initial seed except zero lies on the same orbit, the choice of an initial seed does not affect the randomness for the whole period.

and

Before using genrand( ), sgenrand( ) must be called with a nonzero unsigned long integer as a seed.

@kgryte
Copy link
Member

kgryte commented Mar 20, 2024

Also, unrelated to the documentation bug, I suggest using a different PRNG for seeding (e.g., minstd or minstd-shuffle), in order to ensure that your seeds are independent of your implementation.

@kgryte kgryte added Bug Something isn't working. Documentation Improvements, additions, or changes to documentation. labels Mar 20, 2024
@kgryte kgryte closed this as completed in 09483ae Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working. Documentation Improvements, additions, or changes to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants