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

biased random integers #6

Closed
mfulton26 opened this issue Oct 18, 2021 · 3 comments
Closed

biased random integers #6

mfulton26 opened this issue Oct 18, 2021 · 3 comments

Comments

@mfulton26
Copy link

mfulton26 commented Oct 18, 2021

I can't tell but I believe this applies. Won't random-int provide biased numbers?

Refs:

@sindresorhus
Copy link
Owner

It should be uniform. See: https://stackoverflow.com/a/1527820/64949

@mfulton26
Copy link
Author

That SO answer has the following comment:

Using Math.round() will give you a non-uniform distribution!

So I think it won't be uniform; I'm not sure that's an issue or not. For most purposes it seems like the small bias is acceptable but more sensitive cases (cryptographic, etc.) it would not be.

I wonder if it would be worthwhile to use an implementation similar to the one from Aaron Toponce or to mention in the readme about this.

Thoughts?

Thanks!

@joepie91
Copy link

For most purposes it seems like the small bias is acceptable but more sensitive cases (cryptographic, etc.) it would not be.

Biased or not, the use of Math.random at all makes this module dangerous for any kind of cryptographic use. Math.random is not an unpredictable random number generator, which is one of the requirements for cryptographic use.

So yes, a warning should be added to the README stating that this module should not be used for any sort of cryptographic purpose. Probably the same applies to the 'related modules' listed in the README.

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

No branches or pull requests

3 participants