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

Allow random to return full range #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svanstone-resilient
Copy link

Previously only returned from 0 to 0.5. This removed 2 bits of entropy from the generated cuids.
This is a replacement for Math.random() and as such it should return from 0 to 1 (but never return 1 exactly), therefore lim was also modified.
The returned value now has about 30 to 32 bits of entropy. This is probably enough for this library (it gets truncated to 20 bits later), but you could consider using something like this library:
https://github.com/emilbayes/secure-random-double/blob/master/index.js
Which would allow you to get 51 or 52 bits of entropy into the return value.

Previously only returned from 0 to 0.5. This removed 2 bits of entropy from the generated cuids.
This is a replacement for Math.random() and as such it should return from 0 to 1 (but never return 1 exactly), therefore lim was also modified.
The returned value now has about 30 to 32 bits of entropy. This is probably enough for this library (it gets truncated to 20 bits later), but you could consider using something like this library:
https://github.com/emilbayes/secure-random-double/blob/master/index.js
Which would allow you to get 51 or 52 bits of entropy into the return value.
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.

1 participant