You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure how much this matters for typical use cases, but I think it's worth raising before @std/random is stabilized.
randomSeeded uses a single generated u32 from pcg32, then converts it to a float64 by dividing by u32 max + 1.
For most cases, this is probably fine, but it does mean that the float64's mantissa isn't uniformly entropic, so a consumer expecting a given range of bits to contain entropy might find that expectation disappointed.
You can see from the repeated 3f bytes that Math.random isn't uniformly entropic either (as the exponent and sign bit don't change, i.e. only the 53-bit mantissa contains entropy), but it doesn't contain repeated 00 bytes like randomSeeded does.
The text was updated successfully, but these errors were encountered:
Given these tradeoffs, the "divide by 2^53" approach seems best, even though this means it will actually never emit many of the floats in [0, 1) - that's probably not a problem in practice.
With pcg32, that approach could look something like this:
Uh oh!
There was an error while loading. Please reload this page.
I'm not sure how much this matters for typical use cases, but I think it's worth raising before
@std/random
is stabilized.randomSeeded
uses a single generated u32 from pcg32, then converts it to a float64 by dividing by u32 max + 1.For most cases, this is probably fine, but it does mean that the float64's mantissa isn't uniformly entropic, so a consumer expecting a given range of bits to contain entropy might find that expectation disappointed.
This can be observed as follows:
Example output:
You can see from the repeated
3f
bytes thatMath.random
isn't uniformly entropic either (as the exponent and sign bit don't change, i.e. only the 53-bit mantissa contains entropy), but it doesn't contain repeated00
bytes likerandomSeeded
does.The text was updated successfully, but these errors were encountered: